frontend, localization, bugfix
This commit is contained in:
@@ -160,6 +160,9 @@ class Parameter {
|
||||
if ($value instanceof DateTime) {
|
||||
$this->value = $value;
|
||||
$valid = true;
|
||||
} else if (is_int($value) || (is_string($value) && preg_match("/^\d+$/", $value))) {
|
||||
$this->value = (new \DateTime())->setTimestamp(intval($value));
|
||||
$valid = true;
|
||||
} else {
|
||||
$format = $this->getFormat();
|
||||
$d = DateTime::createFromFormat($format, $value);
|
||||
|
||||
@@ -13,11 +13,15 @@ class StringType extends Parameter {
|
||||
}
|
||||
|
||||
public function parseParam($value): bool {
|
||||
if(!is_string($value)) {
|
||||
if (!parent::parseParam($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($this->maxLength > 0 && strlen($value) > $this->maxLength) {
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->maxLength > 0 && strlen($value) > $this->maxLength) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ abstract class Request {
|
||||
|
||||
if ($this->externalCall) {
|
||||
$values = $_REQUEST;
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_SERVER["CONTENT_TYPE"]) && in_array("application/json", explode(";", $_SERVER["CONTENT_TYPE"]))) {
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && in_array("application/json", explode(";", $_SERVER["CONTENT_TYPE"] ?? ""))) {
|
||||
$jsonData = json_decode(file_get_contents('php://input'), true);
|
||||
if ($jsonData !== null) {
|
||||
$values = array_merge($values, $jsonData);
|
||||
@@ -432,4 +432,42 @@ abstract class Request {
|
||||
return $this->createError("Error processing image: " . $ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected function getFileUpload(string $name, bool $allowMultiple = false, ?array $extensions = null): false|array {
|
||||
if (!isset($_FILES[$name]) || (is_array($_FILES[$name]["name"]) && empty($_FILES[$name]["name"])) || empty($_FILES[$name]["name"])) {
|
||||
return $this->createError("Missing form-field '$name'");
|
||||
}
|
||||
|
||||
$files = [];
|
||||
if (is_array($_FILES[$name]["name"])) {
|
||||
$numFiles = count($_FILES[$name]["name"]);
|
||||
if (!$allowMultiple && $numFiles > 1) {
|
||||
return $this->createError("Only one file allowed for form-field '$name'");
|
||||
} else {
|
||||
for ($i = 0; $i < $numFiles; $i++) {
|
||||
$fileName = $_FILES[$name]["name"][$i];
|
||||
$filePath = $_FILES[$name]["tmp_name"][$i];
|
||||
$files[$fileName] = $filePath;
|
||||
|
||||
if (!empty($extensions) && !in_array(pathinfo($fileName, PATHINFO_EXTENSION), $extensions)) {
|
||||
return $this->createError("File '$fileName' has forbidden extension, allowed: " . implode(",", $extensions));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$fileName = $_FILES[$name]["name"];
|
||||
$filePath = $_FILES[$name]["tmp_name"];
|
||||
$files[$fileName] = $filePath;
|
||||
if (!empty($extensions) && !in_array(pathinfo($fileName, PATHINFO_EXTENSION), $extensions)) {
|
||||
return $this->createError("File '$fileName' has forbidden extension, allowed: " . implode(",", $extensions));
|
||||
}
|
||||
}
|
||||
|
||||
if ($allowMultiple) {
|
||||
return $files;
|
||||
} else {
|
||||
$fileName = key($files);
|
||||
return [$fileName, $files[$fileName]];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user