This commit is contained in:
2023-10-24 17:22:32 +08:00
parent 9c2a349242
commit 9c3c1cfd82
11 changed files with 45 additions and 55 deletions
+3 -4
View File
@@ -1,9 +1,6 @@
<?php <?php
if (class_exists('\ReturnTypeWillChange')) { if (!class_exists('\ReturnTypeWillChange')) {
return;
}
#[\Attribute(\Attribute::TARGET_METHOD)] #[\Attribute(\Attribute::TARGET_METHOD)]
final class ReturnTypeWillChange final class ReturnTypeWillChange
{ {
@@ -14,3 +11,5 @@ final class ReturnTypeWillChange
} }
} }
}
+2
View File
@@ -21,6 +21,8 @@
"ext-xml": "*", "ext-xml": "*",
"ext-curl": "*", "ext-curl": "*",
"ext-openssl": "*", "ext-openssl": "*",
"ext-swoole": "*",
"ext-msgpack": "*",
"symfony/console": "~v5.3.10", "symfony/console": "~v5.3.10",
"psr/log": "1.*", "psr/log": "1.*",
"composer-runtime-api": "^2.0", "composer-runtime-api": "^2.0",
@@ -23,8 +23,6 @@ use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Kiri\Events\EventProvider; use Kiri\Events\EventProvider;
use ReflectionException; use ReflectionException;
use Monolog\Logger;
use Kiri\Pool\{Pool, PoolInterface};
use Kiri\Error\StdoutLogger; use Kiri\Error\StdoutLogger;
/** /**
@@ -82,8 +80,6 @@ abstract class BaseApplication extends Component
} }
const LOGGER_LEVELS = [Logger::EMERGENCY, Logger::ALERT, Logger::CRITICAL, Logger::ERROR, Logger::WARNING, Logger::NOTICE, Logger::INFO, Logger::DEBUG];
/** /**
* @param ConfigProvider $config * @param ConfigProvider $config
* @return void * @return void
+2 -1
View File
@@ -13,6 +13,7 @@ namespace Kiri\Abstracts;
use Exception; use Exception;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
use Kiri; use Kiri;
use ReflectionException;
/** /**
* Class Component * Class Component
@@ -49,7 +50,7 @@ class Component implements Configure
/** /**
* @return Kiri\Error\StdoutLogger * @return Kiri\Error\StdoutLogger
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function getLogger(): Kiri\Error\StdoutLogger public function getLogger(): Kiri\Error\StdoutLogger
{ {
+1 -1
View File
@@ -94,7 +94,7 @@ class DateFormat
* @param null $endTime * @param null $endTime
* @return string * @return string
*/ */
public static function mtime($startTime, $endTime = null) public static function mtime($startTime, $endTime = null): string
{ {
if ($endTime === null) { if ($endTime === null) {
$endTime = microtime(true); $endTime = microtime(true);
+6 -1
View File
@@ -138,7 +138,12 @@ class HashMap implements \ArrayAccess, \IteratorAggregate
} }
public static function Tree(HashMap $root, string $leaf) /**
* @param HashMap $root
* @param string $leaf
* @return HashMap
*/
public static function Tree(HashMap $root, string $leaf): HashMap
{ {
if ($root->has($leaf)) { if ($root->has($leaf)) {
$hashMap = $root->get($leaf); $hashMap = $root->get($leaf);
+8 -9
View File
@@ -6,6 +6,8 @@ namespace Kiri\Core;
use Exception; use Exception;
use Swift_Message;
use Swift_SmtpTransport;
/** /**
@@ -114,10 +116,7 @@ class Help
public static function toString($parameter): bool|array|string public static function toString($parameter): bool|array|string
{ {
if (!is_string($parameter)) { if (!is_string($parameter)) {
$parameter = ArrayAccess::toArray($parameter); $parameter = Json::encode(ArrayAccess::toArray($parameter));
if (is_array($parameter)) {
$parameter = Json::encode($parameter);
}
} }
return $parameter; return $parameter;
} }
@@ -152,7 +151,7 @@ class Help
* *
* 随机字符串 * 随机字符串
*/ */
public static function random($length = 20): string public static function random(int $length = 20): string
{ {
$res = []; $res = [];
$str = 'abcdefghijklmnopqrstuvwxyz'; $str = 'abcdefghijklmnopqrstuvwxyz';
@@ -162,7 +161,7 @@ class Help
if (empty($rand)) { if (empty($rand)) {
$rand = substr($str, strlen($str) - 3, 1); $rand = substr($str, strlen($str) - 3, 1);
} }
array_push($res, $rand); $res[] = $rand;
} }
return implode($res); return implode($res);
@@ -199,14 +198,14 @@ class Help
* @param string $Subject * @param string $Subject
* @param $messageContent * @param $messageContent
*/ */
public static function sendEmail($email, string $Subject, $messageContent) public static function sendEmail($email, string $Subject, $messageContent): void
{ {
if (!class_exists('\Swift_Mailer')) { if (!class_exists('\Swift_Mailer')) {
return; return;
} }
$mailer = new \Swift_Mailer((new \Swift_SmtpTransport($email['host'], $email['port'])) $mailer = new \Swift_Mailer((new Swift_SmtpTransport($email['host'], $email['port']))
->setUsername($email['username'])->setPassword($email['password'])); ->setUsername($email['username'])->setPassword($email['password']));
$message = (new \Swift_Message($Subject)) $message = (new Swift_Message($Subject))
->setFrom([$email['send']['address'] => $email['send']['nickname']]) ->setFrom([$email['send']['address'] => $email['send']['nickname']])
->setBody('Here is the message itself'); ->setBody('Here is the message itself');
+6 -11
View File
@@ -171,17 +171,12 @@ class Str
*/ */
public static function filename($file, $type): string public static function filename($file, $type): string
{ {
switch ($type) { return match ($type) {
case 'image/png': 'image/png' => md5_file($file) . '.png',
return md5_file($file) . '.png'; 'image/jpeg', 'image/jpg' => md5_file($file) . '.jpg',
case 'image/jpeg': 'image/gif' => md5_file($file) . '.gif',
case 'image/jpg': default => md5_file($file),
return md5_file($file) . '.jpg'; };
case 'image/gif':
return md5_file($file) . '.gif';
break;
}
return md5_file($file);
} }
/** /**
-6
View File
@@ -95,8 +95,6 @@ class ErrorHandler extends Component implements ErrorInterface
/** /**
* @return void * @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException * @throws ReflectionException
* @throws Exception * @throws Exception
*/ */
@@ -114,8 +112,6 @@ class ErrorHandler extends Component implements ErrorInterface
/** /**
* @param Throwable $exception * @param Throwable $exception
* *
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws Exception * @throws Exception
*/ */
public function exceptionHandler(Throwable $exception): void public function exceptionHandler(Throwable $exception): void
@@ -130,8 +126,6 @@ class ErrorHandler extends Component implements ErrorInterface
/** /**
* @throws ErrorException * @throws ErrorException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException * @throws ReflectionException
*/ */
public function errorHandler() public function errorHandler()
+1 -1
View File
@@ -9,7 +9,7 @@ class OnAfterCommandExecute
/** /**
* * @param Command $command
*/ */
public function __construct(public Command $command) public function __construct(public Command $command)
{ {
-1
View File
@@ -13,7 +13,6 @@ use Exception;
use Kiri; use Kiri;
use Kiri\Exception\RedisConnectException; use Kiri\Exception\RedisConnectException;
use Kiri\Pool\Pool; use Kiri\Pool\Pool;
use Kiri\Server\Events\OnWorkerExit;
/** /**
* Class Redis * Class Redis