改名
This commit is contained in:
@@ -13,12 +13,8 @@ namespace Kiri\Abstracts;
|
|||||||
use Annotation\Annotation as SAnnotation;
|
use Annotation\Annotation as SAnnotation;
|
||||||
use Database\Connection;
|
use Database\Connection;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Http\Context\HttpHeaders;
|
|
||||||
use Http\Context\HttpParams;
|
|
||||||
use Http\Route\Router;
|
use Http\Route\Router;
|
||||||
use Server\Server;
|
use Server\Server;
|
||||||
use Http\Shutdown;
|
|
||||||
use JetBrains\PhpStorm\Pure;
|
|
||||||
use Kafka\KafkaProvider;
|
use Kafka\KafkaProvider;
|
||||||
use Kiri\AspectManager;
|
use Kiri\AspectManager;
|
||||||
use Kiri\Async;
|
use Kiri\Async;
|
||||||
@@ -465,12 +461,9 @@ abstract class BaseApplication extends Component
|
|||||||
'annotation' => ['class' => SAnnotation::class],
|
'annotation' => ['class' => SAnnotation::class],
|
||||||
'databases' => ['class' => Connection::class],
|
'databases' => ['class' => Connection::class],
|
||||||
'aop' => ['class' => AspectManager::class],
|
'aop' => ['class' => AspectManager::class],
|
||||||
'input' => ['class' => HttpParams::class],
|
|
||||||
'header' => ['class' => HttpHeaders::class],
|
|
||||||
'jwt' => ['class' => Jwt::class],
|
'jwt' => ['class' => Jwt::class],
|
||||||
'async' => ['class' => Async::class],
|
'async' => ['class' => Async::class],
|
||||||
'kafka-container' => ['class' => KafkaProvider::class],
|
'kafka-container' => ['class' => KafkaProvider::class],
|
||||||
'shutdown' => ['class' => Shutdown::class],
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ use Http\Client\Curl;
|
|||||||
use Http\HttpFilter;
|
use Http\HttpFilter;
|
||||||
use Http\Route\Router;
|
use Http\Route\Router;
|
||||||
use Server\Server;
|
use Server\Server;
|
||||||
use Http\Shutdown;
|
|
||||||
use Kiri\Crontab\Producer;
|
use Kiri\Crontab\Producer;
|
||||||
use Kiri\Async;
|
use Kiri\Async;
|
||||||
use Kiri\Error\Logger;
|
use Kiri\Error\Logger;
|
||||||
@@ -34,7 +33,6 @@ use Kiri\Jwt\Jwt;
|
|||||||
* @property Curl $curl
|
* @property Curl $curl
|
||||||
* @property Producer $crontab
|
* @property Producer $crontab
|
||||||
* @property HttpFilter $filter
|
* @property HttpFilter $filter
|
||||||
* @property Shutdown $shutdown
|
|
||||||
*/
|
*/
|
||||||
trait TraitApplication
|
trait TraitApplication
|
||||||
{
|
{
|
||||||
|
|||||||
+18
-2
@@ -101,11 +101,27 @@ class Kiri
|
|||||||
return static::$service;
|
return static::$service;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Application|null
|
||||||
|
*/
|
||||||
|
public static function getApplicationContext(): ?Application
|
||||||
|
{
|
||||||
|
return static::$service;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Container|null
|
||||||
|
*/
|
||||||
|
public static function getContainerContext(): ?Container
|
||||||
|
{
|
||||||
|
return static::$container;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws NotFindClassException
|
|
||||||
* @throws ReflectionException
|
|
||||||
*/
|
*/
|
||||||
public static function has($name): bool
|
public static function has($name): bool
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,133 +0,0 @@
|
|||||||
<?php
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Http\Context;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use Kiri\Kiri;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class File
|
|
||||||
*/
|
|
||||||
class File
|
|
||||||
{
|
|
||||||
|
|
||||||
public string $name = '';
|
|
||||||
public mixed $tmp_name = '';
|
|
||||||
public mixed $error = '';
|
|
||||||
public mixed $type = '';
|
|
||||||
public mixed $size = '';
|
|
||||||
|
|
||||||
|
|
||||||
private string $_content = '';
|
|
||||||
|
|
||||||
private string $newName = '';
|
|
||||||
private array $errorInfo = [
|
|
||||||
0 => 'UPLOAD_ERR_OK.',
|
|
||||||
1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini.',
|
|
||||||
2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
|
|
||||||
3 => 'The uploaded file was only partially uploaded.',
|
|
||||||
4 => 'No file was uploaded.',
|
|
||||||
6 => 'Missing a temporary folder.',
|
|
||||||
7 => 'Failed to write file to disk.',
|
|
||||||
8 => 'A PHP extension stopped the file upload.'
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $path
|
|
||||||
* @return bool
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function saveTo(string $path): bool
|
|
||||||
{
|
|
||||||
if ($this->hasError()) {
|
|
||||||
throw new Exception($this->getErrorInfo());
|
|
||||||
}
|
|
||||||
|
|
||||||
@move_uploaded_file($this->tmp_name, $path);
|
|
||||||
if (!file_exists($path)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function rename(): string
|
|
||||||
{
|
|
||||||
if (!empty($this->newName)) {
|
|
||||||
return $this->newName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!file_exists($this->getTmpPath())) {
|
|
||||||
throw new Exception('(' . $this->name . ')Failed to open stream: No such file or directory');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function getContent(): string
|
|
||||||
{
|
|
||||||
$open = fopen($this->getTmpPath(), 'r');
|
|
||||||
|
|
||||||
// @move_uploaded_file($this->tmp_name, storage($this->name));
|
|
||||||
|
|
||||||
$limit = 1024000;
|
|
||||||
|
|
||||||
$stat = fstat($open);
|
|
||||||
|
|
||||||
$sleep = $offset = 0;
|
|
||||||
$content = '';
|
|
||||||
while ($file = fread($open, $limit)) {
|
|
||||||
$content .= $file;
|
|
||||||
fseek($open, $offset);
|
|
||||||
if ($sleep > 0) {
|
|
||||||
sleep($sleep);
|
|
||||||
}
|
|
||||||
if ($offset >= $stat['size']) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$offset += $limit;
|
|
||||||
}
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getTmpPath(): string
|
|
||||||
{
|
|
||||||
return $this->tmp_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* check file have error
|
|
||||||
*/
|
|
||||||
public function hasError(): bool
|
|
||||||
{
|
|
||||||
return $this->error !== 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return mixed
|
|
||||||
*
|
|
||||||
* get upload error info
|
|
||||||
*/
|
|
||||||
public function getErrorInfo(): mixed
|
|
||||||
{
|
|
||||||
if (!isset($this->errorInfo[$this->error])) {
|
|
||||||
return 'Unknown upload error.';
|
|
||||||
}
|
|
||||||
return $this->errorInfo[$this->error];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: admin
|
|
||||||
* Date: 2019-03-18
|
|
||||||
* Time: 14:54
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Http\Context;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class HttpHeaders
|
|
||||||
* @package Kiri\Kiri\Http
|
|
||||||
*/
|
|
||||||
trait HttpHeaders
|
|
||||||
{
|
|
||||||
|
|
||||||
private array $_headers = [];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private array $_server = [];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $headers
|
|
||||||
*/
|
|
||||||
public function setHeaders(array $headers): void
|
|
||||||
{
|
|
||||||
$this->_headers = $headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function toArray(): array
|
|
||||||
{
|
|
||||||
return $this->_headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $name
|
|
||||||
* @param null $default
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getHeader($name, $default = null): mixed
|
|
||||||
{
|
|
||||||
return $this->_headers[$name] ?? $default;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $name
|
|
||||||
* @param $default
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function header($name, $default = null): mixed
|
|
||||||
{
|
|
||||||
return $this->getHeader($name, $default);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getContentType(): string
|
|
||||||
{
|
|
||||||
return $this->_headers['content-type'] ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string|null
|
|
||||||
*/
|
|
||||||
public function getRequestUri(): ?string
|
|
||||||
{
|
|
||||||
return $this->_headers['request_uri'];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string|null
|
|
||||||
*/
|
|
||||||
public function getRequestMethod(): ?string
|
|
||||||
{
|
|
||||||
return $this->_headers['request_method'];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getAgent(): mixed
|
|
||||||
{
|
|
||||||
return $this->_headers['user-agent'];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $name
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function exists($name): bool
|
|
||||||
{
|
|
||||||
return ($this->_headers[$name] ?? null) === null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getHeaders(): array
|
|
||||||
{
|
|
||||||
return $this->_headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,402 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: admin
|
|
||||||
* Date: 2019-03-18
|
|
||||||
* Time: 14:54
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Http\Context;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use Http\Exception\RequestException;
|
|
||||||
use Kiri\Core\Json;
|
|
||||||
use Kiri\Core\Xml;
|
|
||||||
use Kiri\Exception\NotFindClassException;
|
|
||||||
use Kiri\Kiri;
|
|
||||||
use ReflectionException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class HttpParams
|
|
||||||
* @package Kiri\Kiri\Http
|
|
||||||
*/
|
|
||||||
trait HttpParams
|
|
||||||
{
|
|
||||||
|
|
||||||
/** @var array|null */
|
|
||||||
private ?array $_gets = [];
|
|
||||||
|
|
||||||
|
|
||||||
/** @var mixed */
|
|
||||||
private mixed $_posts = [];
|
|
||||||
|
|
||||||
|
|
||||||
/** @var array|null */
|
|
||||||
private ?array $_files = [];
|
|
||||||
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
private string $_body = '';
|
|
||||||
|
|
||||||
|
|
||||||
private mixed $_rawContent = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array|null $gets
|
|
||||||
*/
|
|
||||||
public function setGets(?array $gets): void
|
|
||||||
{
|
|
||||||
$this->_gets = $gets;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $posts
|
|
||||||
*/
|
|
||||||
public function setPosts(mixed $posts): void
|
|
||||||
{
|
|
||||||
$this->_posts = $posts;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array|null $files
|
|
||||||
*/
|
|
||||||
public function setFiles(?array $files): void
|
|
||||||
{
|
|
||||||
$this->_files = $files;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \Swoole\Http\Request $request
|
|
||||||
*/
|
|
||||||
public function setParseBody(\Swoole\Http\Request $request): void
|
|
||||||
{
|
|
||||||
$content = $request->getContent();
|
|
||||||
if (empty($content)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$contentType = $request->header['content-type'];
|
|
||||||
if (str_contains($contentType, 'json')) {
|
|
||||||
$this->_posts = json_decode($contentType, true);
|
|
||||||
} else if (str_contains($contentType, 'xml')) {
|
|
||||||
$this->_posts = Xml::toArray($contentType);
|
|
||||||
} else if (str_contains($contentType, 'x-www-form-urlencoded')) {
|
|
||||||
$this->_posts = $request->post;
|
|
||||||
} else if (str_contains($contentType, 'serialize')) {
|
|
||||||
$this->_posts = unserialize($content);
|
|
||||||
} else {
|
|
||||||
$this->_body = $content;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function getContent(): string
|
|
||||||
{
|
|
||||||
return $this->_body;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function offset(): int
|
|
||||||
{
|
|
||||||
return ($this->page() - 1) * $this->size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array|null
|
|
||||||
*/
|
|
||||||
public function getBody(): ?array
|
|
||||||
{
|
|
||||||
return $this->_posts;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
private function page(): int
|
|
||||||
{
|
|
||||||
return (int)$this->query('page', 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $name
|
|
||||||
* @param null $default
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function query($name = null, $default = null): mixed
|
|
||||||
{
|
|
||||||
if (!empty($name)) {
|
|
||||||
return $this->_gets[$name] ?? $default;
|
|
||||||
}
|
|
||||||
return $this->_gets;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function size(): int
|
|
||||||
{
|
|
||||||
return (int)$this->query('size', 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $name
|
|
||||||
* @param null $defaultValue
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function post($name, $defaultValue = null): mixed
|
|
||||||
{
|
|
||||||
return $this->_posts[$name] ?? $defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $name
|
|
||||||
* @return bool|string
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function json($name): bool|string
|
|
||||||
{
|
|
||||||
$data = $this->array($name);
|
|
||||||
if (empty($data)) {
|
|
||||||
return Json::encode([]);
|
|
||||||
} else if (!is_array($data)) {
|
|
||||||
return Json::encode([]);
|
|
||||||
}
|
|
||||||
return Json::encode($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function gets(): array
|
|
||||||
{
|
|
||||||
return $this->_gets;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function params(): array
|
|
||||||
{
|
|
||||||
return array_merge($this->_gets, $this->_posts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function load(): array
|
|
||||||
{
|
|
||||||
return array_merge($this->_files, $this->_gets, $this->_posts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $name
|
|
||||||
* @param array $defaultValue
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function array($name, array $defaultValue = []): mixed
|
|
||||||
{
|
|
||||||
return $this->_posts[$name] = $defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $name
|
|
||||||
* @return File|null
|
|
||||||
* @throws ReflectionException
|
|
||||||
* @throws NotFindClassException
|
|
||||||
*/
|
|
||||||
public function file($name): File|null
|
|
||||||
{
|
|
||||||
$param = $this->_files[$name] ?? null;
|
|
||||||
if (!empty($param)) {
|
|
||||||
$param['class'] = File::class;
|
|
||||||
return Kiri::createObject($param);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param bool $isNeed
|
|
||||||
* @return mixed
|
|
||||||
* @throws RequestException
|
|
||||||
*/
|
|
||||||
private function required(string $name, bool $isNeed = false): mixed
|
|
||||||
{
|
|
||||||
$int = $this->_posts[$name] ?? null;
|
|
||||||
if (is_null($int) && $isNeed === true) {
|
|
||||||
throw new RequestException("You need to add request parameter $name");
|
|
||||||
}
|
|
||||||
return $int;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param bool $isNeed
|
|
||||||
* @param array|int|null $min
|
|
||||||
* @param int|null $max
|
|
||||||
* @return int|null
|
|
||||||
* @throws RequestException
|
|
||||||
*/
|
|
||||||
public function int(string $name, bool $isNeed = FALSE, array|int|null $min = NULL, int|null $max = NULL): ?int
|
|
||||||
{
|
|
||||||
return (int)$this->required($name, $isNeed);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param bool $isNeed
|
|
||||||
* @param int $round
|
|
||||||
* @return float|null
|
|
||||||
* @throws RequestException
|
|
||||||
*/
|
|
||||||
public function float(string $name, bool $isNeed = FALSE, int $round = 0): ?float
|
|
||||||
{
|
|
||||||
return (float)$this->required($name, $isNeed);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param bool $isNeed
|
|
||||||
* @param int|array|null $length
|
|
||||||
*
|
|
||||||
* @return string|null
|
|
||||||
* @throws RequestException
|
|
||||||
*/
|
|
||||||
public function string(string $name, bool $isNeed = FALSE, int|array|null $length = NULL): ?string
|
|
||||||
{
|
|
||||||
return (string)$this->required($name, $isNeed);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param bool $isNeed
|
|
||||||
*
|
|
||||||
* @return string|null
|
|
||||||
* @throws RequestException
|
|
||||||
*/
|
|
||||||
public function email(string $name, bool $isNeed = FALSE): ?string
|
|
||||||
{
|
|
||||||
$email = $this->required($name, $isNeed);
|
|
||||||
if ($email === null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!preg_match('/^\w+([.-_]\w+)+@\w+(\.\w+)+$/', $email)) {
|
|
||||||
throw new RequestException("Request parameter $name is in the wrong format", 4001);
|
|
||||||
}
|
|
||||||
return $email;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param bool $isNeed
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
* @throws RequestException
|
|
||||||
*/
|
|
||||||
public function bool(string $name, bool $isNeed = FALSE): bool
|
|
||||||
{
|
|
||||||
return (boolean)$this->required($name, $isNeed);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param int|null $default
|
|
||||||
*
|
|
||||||
* @return int|string|null
|
|
||||||
* @throws RequestException
|
|
||||||
*/
|
|
||||||
public function timestamp(string $name, int|null $default = NULL): null|int|string
|
|
||||||
{
|
|
||||||
$value = $this->required($name, false);
|
|
||||||
if ($value === null) {
|
|
||||||
return $default;
|
|
||||||
}
|
|
||||||
if (!is_numeric($value)) {
|
|
||||||
throw new RequestException('The request param :attribute not is a timestamp value');
|
|
||||||
}
|
|
||||||
if (strlen((string)$value) != 10) {
|
|
||||||
throw new RequestException('The request param :attribute not is a timestamp value');
|
|
||||||
}
|
|
||||||
if (!date('YmdHis', $value)) {
|
|
||||||
throw new RequestException('The request param :attribute format error', 4001);
|
|
||||||
}
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param string|null $default
|
|
||||||
*
|
|
||||||
* @return string|null
|
|
||||||
* @throws RequestException
|
|
||||||
*/
|
|
||||||
public function datetime(string $name, string $default = NULL): string|null
|
|
||||||
{
|
|
||||||
$value = $this->required($name, false);
|
|
||||||
if ($value === null) {
|
|
||||||
return $default;
|
|
||||||
}
|
|
||||||
$match = '/^\d{4}.*?([1-12]).*([1-31]).*?[0-23].*?[0-59].*?[0-59].*?$/';
|
|
||||||
$match = preg_match($match, $value, $result);
|
|
||||||
if (!$match || $result[0] != $value) {
|
|
||||||
throw new RequestException('The request param :attribute format error', 4001);
|
|
||||||
}
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param string|null $default
|
|
||||||
*
|
|
||||||
* @return string|null
|
|
||||||
* @throws RequestException
|
|
||||||
*/
|
|
||||||
public function date(string $name, string $default = NULL): string|null
|
|
||||||
{
|
|
||||||
$value = $this->required($name, false);
|
|
||||||
if ($value === null) {
|
|
||||||
return $default;
|
|
||||||
}
|
|
||||||
$match = '/^\d{4}.*?([1-12]).*([1-31])$/';
|
|
||||||
$match = preg_match($match, $value, $result);
|
|
||||||
if (!$match || $result[0] != $value) {
|
|
||||||
throw new RequestException('The request param :attribute format error', 4001);
|
|
||||||
}
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param string|null $default
|
|
||||||
* @return string|null
|
|
||||||
* @throws RequestException
|
|
||||||
*/
|
|
||||||
public function ip(string $name, string $default = NULL): string|null
|
|
||||||
{
|
|
||||||
$value = $this->required($name, false);
|
|
||||||
if ($value == NULL) {
|
|
||||||
return $default;
|
|
||||||
}
|
|
||||||
$match = preg_match('/^\d{1,3}(\.\d{1,3}){3}$/', $value, $result);
|
|
||||||
if (!$match || $result[0] != $value) {
|
|
||||||
throw new RequestException('The request param :attribute format error', 4001);
|
|
||||||
}
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -20,14 +20,6 @@ class Controller
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Application $application
|
|
||||||
*/
|
|
||||||
#[Pure] public function __construct(protected Application $application)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inject di container
|
* inject di container
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ use Server\Constrict\ResponseInterface;
|
|||||||
use Server\SInterface\DownloadInterface;
|
use Server\SInterface\DownloadInterface;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
class Response implements ResponseInterface
|
class Response implements ResponseInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user