Revert "改名"

This reverts commit fdf58326
This commit is contained in:
2022-01-08 18:49:08 +08:00
parent 7165a67294
commit 97cd1a0ebf
33 changed files with 169 additions and 172 deletions
+4 -3
View File
@@ -9,7 +9,7 @@
],
"license": "MIT",
"require": {
"php": ">=8.0",
"php": ">=8.1",
"ext-json": "*",
"ext-fileinfo": "*",
"ext-pdo": "*",
@@ -27,7 +27,6 @@
"ext-pcntl": "*",
"ext-posix": "*",
"composer-runtime-api": "^2.0",
"swiftmailer/swiftmailer": "v6.3.*",
"psr/container": "^2.0",
"psr/http-server-middleware": "1.0.1",
"game-worker/kiri-event": "^v1.0",
@@ -37,8 +36,10 @@
"psr-4": {
"Kiri\\": "kiri-engine/",
"Kiri\\Gateway\\": "kiri-gateway/",
"Kiri\\Websocket\\": "kiri-websocket-server/",
"Gii\\": "kiri-gii/",
"Note\\": "kiri-note/"
"Kiri\\Annotation\\": "kiri-annotation/",
"Kiri\\Task\\": "kiri-task/"
},
"files": [
"error.php",
+10 -10
View File
@@ -8,14 +8,14 @@ use JetBrains\PhpStorm\Pure;
use Kiri\Abstracts\Config;
use Kiri\Application;
use Kiri\Core\ArrayAccess;
use Kiri\Di\NoteManager;
use Kiri\Di\AnnotationManager;
use Kiri\Error\Logger;
use Kiri\Events\EventDispatch;
use Kiri\Events\EventProvider;
use Kiri\Exception\ConfigException;
use Kiri\Kiri;
use Note\Note;
use Note\Route\Route;
use Kiri\Annotation\Annotation;
use Kiri\Annotation\Route\Route;
use Psr\Log\LoggerInterface;
use Swoole\Process;
use Swoole\WebSocket\Server;
@@ -192,16 +192,16 @@ if (!function_exists('workerName')) {
}
if (!function_exists('note')) {
if (!function_exists('Annotation')) {
/**
* @return Note
* @return Annotation
* @throws Exception
*/
function annotation(): Note
function annotation(): Annotation
{
return Kiri::getNote();
return Kiri::getAnnotation();
}
@@ -220,7 +220,7 @@ if (!function_exists('scan_directory')) {
*/
function scan_directory($dir, $namespace, array $exclude = [])
{
$annotation = Kiri::app()->getNote();
$annotation = Kiri::app()->getAnnotation();
$annotation->read($dir, $namespace, $exclude);
injectRuntime($dir, $exclude);
@@ -256,12 +256,12 @@ if (!function_exists('injectRuntime')) {
*/
function injectRuntime(string $path, array $exclude = [])
{
$fileLists = Kiri::getNote()->runtime($path, $exclude);
$fileLists = Kiri::getAnnotation()->runtime($path, $exclude);
$di = Kiri::getDi();
$router = [];
foreach ($fileLists as $class) {
foreach (NoteManager::getTargetNote($class) as $value) {
foreach (AnnotationManager::getTargetAnnotation($class) as $value) {
if (!method_exists($value, 'execute')) {
continue;
}
@@ -1,7 +1,7 @@
<?php
namespace Note;
namespace Kiri\Annotation;
use DirectoryIterator;
@@ -10,10 +10,10 @@ use ReflectionException;
use Kiri\Abstracts\Component;
/**
* Class Note
* @package Note
* Class Annotation
* @package Annotation
*/
class Note extends Component
class Annotation extends Component
{
@@ -1,7 +1,7 @@
<?php
namespace Note;
namespace Kiri\Annotation;
use Exception;
@@ -10,7 +10,7 @@ defined('ASPECT_ERROR') or define('ASPECT_ERROR', 'Aspect annotation must implem
/**
* Class Aspect
* @package Note
* @package Annotation
*/
#[\Attribute(\Attribute::TARGET_METHOD)] class Aspect extends Attribute
{
@@ -1,14 +1,14 @@
<?php
namespace Note;
namespace Kiri\Annotation;
/**
* Class Attribute
* @package Note
* @package Annotation
*/
abstract class Attribute implements INote
abstract class Attribute implements IAnnotation
{
@@ -1,7 +1,7 @@
<?php
namespace Note;
namespace Kiri\Annotation;
use Exception;
@@ -11,7 +11,7 @@ use Kiri\Kiri;
/**
* Class Event
* @package Note
* @package Annotation
*/
#[\Attribute(\Attribute::TARGET_METHOD)] class Event extends Attribute
{
@@ -1,11 +1,11 @@
<?php
namespace Note;
namespace Kiri\Annotation;
interface INote
interface IAnnotation
{
/**
@@ -1,7 +1,7 @@
<?php
namespace Note;
namespace Kiri\Annotation;
use Exception;
@@ -12,7 +12,7 @@ use ReflectionProperty;
/**
* Class Inject
* @package Note
* @package Annotation
*/
#[\Attribute(\Attribute::TARGET_PROPERTY)] class Inject extends Attribute
{
@@ -70,7 +70,6 @@ use ReflectionProperty;
* @param $class
* @param $method
* @return ReflectionProperty|bool
* @throws ReflectionException
*/
private function getProperty($class, $method): ReflectionProperty|bool
{
@@ -1,7 +1,7 @@
<?php
namespace Note;
namespace Kiri\Annotation;
use DirectoryIterator;
@@ -15,21 +15,15 @@ use Throwable;
/**
* Class Loader
* @package Note
* @package Annotation
*/
class Loader extends Component
{
private array $_classes = [];
private array $_directory = [];
private array $_property = [];
private array $_methods = [];
@@ -43,17 +37,6 @@ class Loader extends Component
$this->_scanDir(new DirectoryIterator($path), $namespace);
}
/**
* @param string $class
* @param string $property
* @return \ReflectionProperty|array|null
* @throws ReflectionException
*/
public function getProperty(string $class, string $property = ''): \ReflectionProperty|array|null
{
return Kiri::getDi()->getClassReflectionProperty($class, $property);
}
/**
* @param string $class
@@ -147,7 +130,6 @@ class Loader extends Component
* @param DirectoryIterator $path
* @param string $namespace
* @return ReflectionClass|null
* @throws ReflectionException
*/
private function getReflect(DirectoryIterator $path, string $namespace): ?ReflectionClass
{
@@ -1,6 +1,6 @@
<?php
namespace Note;
namespace Kiri\Annotation;
use Kiri\Kiri;
@@ -1,14 +1,14 @@
<?php
namespace Note\Route;
namespace Kiri\Annotation\Route;
use Note\Attribute;
use Kiri\Annotation\Attribute;
/**
* Class Document
* @package Note\Route
* @package Annotation\Route
*/
#[\Attribute(\Attribute::TARGET_METHOD)] class Document extends Attribute
{
@@ -1,16 +1,16 @@
<?php
namespace Note\Route;
namespace Kiri\Annotation\Route;
use Note\Attribute;
use Kiri\Annotation\Attribute;
use Http\Handler\Abstracts\MiddlewareManager;
use Psr\Http\Server\MiddlewareInterface;
/**
* Class Middleware
* @package Note\Route
* @package Annotation\Route
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] class Middleware extends Attribute
{
@@ -1,10 +1,10 @@
<?php
namespace Note\Route;
namespace Kiri\Annotation\Route;
use Note\Attribute;
use Kiri\Annotation\Attribute;
use Http\Handler\Router;
use Kiri\Kiri;
@@ -1,14 +1,14 @@
<?php
namespace Note\Route;
namespace Kiri\Annotation\Route;
use Note\Attribute;
use Kiri\Annotation\Attribute;
/**
* Class Socket
* @package Note
* @package Annotation
*/
#[\Attribute(\Attribute::TARGET_METHOD)] class Socket extends Attribute
{
@@ -1,12 +1,12 @@
<?php
namespace Note;
namespace Kiri\Annotation;
/**
* Class Target
* @package Note
* @package Annotation
*/
#[\Attribute(\Attribute::TARGET_CLASS)] class Target extends Attribute
{
@@ -1,7 +1,7 @@
<?php
namespace Note;
namespace Kiri\Annotation;
use Exception;
@@ -11,7 +11,7 @@ use Server\Tasker\AsyncTaskExecute;
/**
* Class Task
* @package Note
* @package Annotation
* Task任务
*/
#[\Attribute(\Attribute::TARGET_CLASS)] class Task extends Attribute
+9 -18
View File
@@ -10,26 +10,18 @@ declare(strict_types=1);
namespace Kiri\Abstracts;
use Note\Note as SNote;
use Database\Connection;
use Exception;
use Http\Handler\Router;
use Kiri\Events\OnBeforeCommandExecute;
use Server\Server;
use Kafka\KafkaProvider;
use Kiri\Async;
use Kiri\{Async, Kiri};
use Kiri\Annotation\Annotation as SAnnotation;
use Kiri\Cache\Redis;
use Kiri\Di\LocalService;
use Kiri\Error\ErrorHandler;
use Kiri\Error\Logger;
use Kiri\Events\EventProvider;
use Kiri\Exception\InitException;
use Kiri\Exception\NotFindClassException;
use Kiri\Kiri;
use Kiri\Error\{ErrorHandler, Logger};
use Kiri\Exception\{InitException, NotFindClassException};
use ReflectionException;
use Server\ServerManager;
use Server\Contract\OnTaskInterface;
use Server\Tasker\AsyncTaskExecute;
use Server\{Contract\OnTaskInterface, Server, ServerManager, Tasker\AsyncTaskExecute};
use Swoole\Table;
/**
@@ -392,12 +384,12 @@ abstract class BaseApplication extends Component
/**
* @return SNote
* @return SAnnotation
* @throws
*/
public function getNote(): SNote
public function getAnnotation(): SAnnotation
{
return $this->get('note');
return $this->get('Annotation');
}
@@ -411,7 +403,6 @@ abstract class BaseApplication extends Component
}
/**
* @param $array
*/
@@ -450,7 +441,7 @@ abstract class BaseApplication extends Component
'error' => ['class' => ErrorHandler::class],
'config' => ['class' => Config::class],
'logger' => ['class' => Logger::class],
'note' => ['class' => SNote::class],
'Annotation' => ['class' => SAnnotation::class],
'databases' => ['class' => Connection::class],
'jwt' => ['class' => Jwt::class],
'async' => ['class' => Async::class],
+2 -7
View File
@@ -4,14 +4,11 @@
namespace Kiri\Abstracts;
use Note\Note as SNote;
use Kiri\Annotation\Annotation as SAnnotation;
use Database\Connection;
use Database\DatabasesProviders;
use Http\Handler\Client\Client;
use Http\Handler\Client\Curl;
use Http\Handler\Router;
use Server\Server;
use Kiri\Crontab\Producer;
use Kiri\Async;
use Kiri\Error\Logger;
use Kiri\Jwt\JWTAuth;
@@ -25,11 +22,9 @@ use Kiri\Jwt\JWTAuth;
* @property Async $async
* @property Logger $logger
* @property JWTAuth $jwt
* @property SNote $annotation
* @property SAnnotation $annotation
* @property BaseGoto $goto
* @property Client $client
* @property Connection $databases
* @property Curl $curl
*/
trait TraitApplication
{
+9 -16
View File
@@ -13,25 +13,22 @@ namespace Kiri;
use Closure;
use Database\DatabasesProviders;
use Exception;
use Kiri\Abstracts\BaseApplication;
use Kiri\Abstracts\Config;
use Kiri\Abstracts\Kernel;
use Kiri\Abstracts\{BaseApplication, Config, Kernel};
use Kiri\Crontab\CrontabProviders;
use Kiri\Events\OnAfterCommandExecute;
use Kiri\Events\OnBeforeCommandExecute;
use Kiri\Exception\NotFindClassException;
use Kiri\Events\{OnAfterCommandExecute, OnBeforeCommandExecute};
use Kiri\FileListen\HotReload;
use ReflectionException;
use Server\ServerProviders;
use stdClass;
use Swoole\Process;
use Swoole\Timer;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\{Application as ConsoleApplication,
Command\Command,
Input\ArgvInput,
Input\InputInterface,
Output\ConsoleOutput,
Output\OutputInterface
};
/**
* Class Init
@@ -213,7 +210,6 @@ class Application extends BaseApplication
}
/**
* @param $argv
* @return array
@@ -224,7 +220,6 @@ class Application extends BaseApplication
}
/**
* @throws ReflectionException
* @throws Exception
@@ -244,8 +239,6 @@ class Application extends BaseApplication
}
/**
* @param $className
* @param null $abstracts
+1 -1
View File
@@ -17,7 +17,7 @@ use Kiri\Events\EventProvider;
use Kiri\Exception\ConfigException;
use Kiri\Kiri;
use Kiri\Pool\Redis as PoolRedis;
use Note\Inject;
use Kiri\Annotation\Inject;
use Server\Events\OnWorkerExit;
use Swoole\Timer;
+6 -6
View File
@@ -9,7 +9,7 @@ declare(strict_types=1);
namespace Kiri\Di;
use Note\Inject;
use Kiri\Annotation\Inject;
use Closure;
use Exception;
use Kiri\Abstracts\Logger;
@@ -197,7 +197,7 @@ class Container implements ContainerInterface
*/
public function propertyInject(ReflectionClass $reflect, $object): mixed
{
foreach (NoteManager::getPropertyNote($reflect) as $property => $inject) {
foreach (AnnotationManager::getPropertyAnnotation($reflect) as $property => $inject) {
/** @var Inject $inject */
$inject->execute($object, $property);
}
@@ -212,7 +212,7 @@ class Container implements ContainerInterface
*/
public function getMethodAttribute($className, $method = null): array
{
$methods = NoteManager::getMethodNote($this->getReflect($className));
$methods = AnnotationManager::getMethodAnnotation($this->getReflect($className));
if (!empty($method)) {
return $methods[$method] ?? [];
}
@@ -227,7 +227,7 @@ class Container implements ContainerInterface
*/
public function getClassReflectionProperty(string $class, string $property = null): ReflectionProperty|null|array
{
$lists = NoteManager::getProperty($this->getReflect($class));
$lists = AnnotationManager::getProperty($this->getReflect($class));
if (empty($lists)) {
return null;
}
@@ -266,7 +266,7 @@ class Container implements ContainerInterface
if ($reflect->isAbstract() || $reflect->isTrait() || $reflect->isInterface()) {
return $this->_reflection[$class] = $reflect;
}
$construct = NoteManager::resolveTarget($reflect);
$construct = AnnotationManager::resolveTarget($reflect);
if (!empty($construct) && $construct->getNumberOfParameters() > 0) {
$this->_constructs[$class] = $construct;
}
@@ -284,7 +284,7 @@ class Container implements ContainerInterface
if (is_string($class)) {
$class = $this->getReflect($class);
}
return NoteManager::getMethods($class);
return AnnotationManager::getMethods($class);
}
+22 -22
View File
@@ -7,14 +7,14 @@ use ReflectionAttribute;
use ReflectionClass;
use ReflectionProperty;
class NoteManager
class AnnotationManager
{
private static array $_classTarget = [];
private static array $_classMethodNote = [];
private static array $_classMethodAnnotation = [];
private static array $_classMethod = [];
private static array $_classPropertyNote = [];
private static array $_classPropertyAnnotation = [];
private static array $_classProperty = [];
private static array $_mapping = [];
@@ -25,9 +25,9 @@ class NoteManager
public static function clear()
{
static::$_classTarget = [];
static::$_classMethodNote = [];
static::$_classMethodAnnotation = [];
static::$_classMethod = [];
static::$_classPropertyNote = [];
static::$_classPropertyAnnotation = [];
static::$_classProperty = [];
static::$_mapping = [];
}
@@ -36,7 +36,7 @@ class NoteManager
/**
* @param ReflectionClass $class
*/
public static function setTargetNote(ReflectionClass $class)
public static function setTargetAnnotation(ReflectionClass $class)
{
$className = $class->getName();
if (!isset(static::$_classTarget[$className])) {
@@ -111,7 +111,7 @@ class NoteManager
* @param mixed $class
* @return array
*/
public static function getTargetNote(mixed $class): array
public static function getTargetAnnotation(mixed $class): array
{
if (!is_string($class)) {
$class = $class::class;
@@ -123,20 +123,20 @@ class NoteManager
/**
* @param ReflectionClass $class
*/
public static function setMethodNote(ReflectionClass $class)
public static function setMethodAnnotation(ReflectionClass $class)
{
$className = $class->getName();
static::$_classMethodNote[$className] = static::$_classMethod[$className] = [];
static::$_classMethodAnnotation[$className] = static::$_classMethod[$className] = [];
foreach ($class->getMethods() as $ReflectionMethod) {
static::$_classMethod[$className][$ReflectionMethod->getName()] = $ReflectionMethod;
static::$_classMethodNote[$className][$ReflectionMethod->getName()] = [];
static::$_classMethodAnnotation[$className][$ReflectionMethod->getName()] = [];
foreach ($ReflectionMethod->getAttributes() as $attribute) {
if (!class_exists($attribute->getName())) {
continue;
}
$instance = $attribute->newInstance();
static::$_classMethodNote[$className][$ReflectionMethod->getName()][] = $instance;
static::$_classMethodAnnotation[$className][$ReflectionMethod->getName()][] = $instance;
self::setMappingMethod($attribute, $className, $ReflectionMethod->getName(), $instance);
}
@@ -159,9 +159,9 @@ class NoteManager
* @param ReflectionClass $class
* @return array
*/
#[Pure] public static function getMethodNote(ReflectionClass $class): array
#[Pure] public static function getMethodAnnotation(ReflectionClass $class): array
{
return static::$_classMethodNote[$class->getName()] ?? [];
return static::$_classMethodAnnotation[$class->getName()] ?? [];
}
@@ -171,9 +171,9 @@ class NoteManager
*/
public static function resolveTarget(ReflectionClass $reflect): ?\ReflectionMethod
{
NoteManager::setPropertyNote($reflect);
NoteManager::setTargetNote($reflect);
NoteManager::setMethodNote($reflect);
AnnotationManager::setPropertyAnnotation($reflect);
AnnotationManager::setTargetAnnotation($reflect);
AnnotationManager::setMethodAnnotation($reflect);
return $reflect->getConstructor();
}
@@ -182,10 +182,10 @@ class NoteManager
/**
* @param ReflectionClass $class
*/
public static function setPropertyNote(ReflectionClass $class)
public static function setPropertyAnnotation(ReflectionClass $class)
{
$className = $class->getName();
static::$_classProperty[$className] = static::$_classPropertyNote[$className] = [];
static::$_classProperty[$className] = static::$_classPropertyAnnotation[$className] = [];
foreach ($class->getProperties(ReflectionProperty::IS_PRIVATE | ReflectionProperty::IS_PUBLIC |
ReflectionProperty::IS_PROTECTED) as $ReflectionMethod) {
static::$_classProperty[$className][$ReflectionMethod->getName()] = $ReflectionMethod;
@@ -196,7 +196,7 @@ class NoteManager
$instance = $attribute->newInstance();
static::$_classPropertyNote[$className][$ReflectionMethod->getName()] = $instance;
static::$_classPropertyAnnotation[$className][$ReflectionMethod->getName()] = $instance;
self::setMappingProperty($attribute, $className, $ReflectionMethod->getName(), $instance);
}
@@ -250,7 +250,7 @@ class NoteManager
* @param string $method
* @return mixed
*/
public static function getPropertyByNote(string $attribute, string $class, string $method): mixed
public static function getPropertyByAnnotation(string $attribute, string $class, string $method): mixed
{
$class = self::getAttributeTrees($attribute, $class);
if (empty($class) || !isset($class['property'])) {
@@ -294,9 +294,9 @@ class NoteManager
* @param ReflectionClass $class
* @return array
*/
#[Pure] public static function getPropertyNote(ReflectionClass $class): array
#[Pure] public static function getPropertyAnnotation(ReflectionClass $class): array
{
return static::$_classPropertyNote[$class->getName()] ?? [];
return static::$_classPropertyAnnotation[$class->getName()] ?? [];
}
+1 -1
View File
@@ -13,7 +13,7 @@ use Exception;
use Kiri\Abstracts\Component;
use Kiri\Core\Json;
use Kiri\Kiri;
use Note\Inject;
use Kiri\Annotation\Inject;
use Psr\Log\LoggerInterface;
use Throwable;
+1 -1
View File
@@ -8,7 +8,7 @@ use Kiri\Core\Json;
use Kiri\Error\Logger;
use Kiri\Exception\ConfigException;
use Kiri\Kiri;
use Note\Inject;
use Kiri\Annotation\Inject;
use Swoole\Coroutine;
use Swoole\Process;
use Swoole\Timer;
+4 -4
View File
@@ -7,7 +7,7 @@ namespace Kiri;
error_reporting(0);
use Note\Note;
use Kiri\Annotation\Annotation;
use Database\Collection;
use Database\ModelInterface;
use Exception;
@@ -159,12 +159,12 @@ class Kiri
/**
* @return Note
* @return Annotation
* @throws Exception
*/
public static function getNote(): Note
public static function getAnnotation(): Annotation
{
return static::app()->getNote();
return static::app()->getAnnotation();
}
+1 -1
View File
@@ -44,7 +44,7 @@ class Runtime extends Command
public function execute(InputInterface $input, OutputInterface $output): int
{
// TODO: Implement onHandler() method.
$annotation = Kiri::app()->getNote();
$annotation = Kiri::app()->getAnnotation();
$runtime = storage(static::CACHE_NAME);
$config = storage(static::CONFIG_NAME);
+3 -3
View File
@@ -65,9 +65,9 @@ namespace {$namespace};
} else {
$import = "use Kiri;
use Exception;
use Note\Target;
use Note\Route\Middleware;
use Note\Route\Route;
use Kiri\Annotation\Target;
use Kiri\Annotation\Route\Middleware;
use Kiri\Annotation\Route\Route;
use Kiri\Core\Str;
use Kiri\Core\Json;
use Http\Context\Request;
+4 -4
View File
@@ -51,8 +51,8 @@ interface ' . ucfirst($name) . 'RpcInterface
namespace Rpc\Producers;
use Note\Target;
use Note\Mapping;
use Kiri\Annotation\Target;
use Kiri\Annotation\Mapping;
use Rpc\\' . ucfirst($name) . 'RpcInterface;
use Exception;
use Kiri\Rpc\JsonRpcConsumers;
@@ -86,8 +86,8 @@ class ' . ucfirst($name) . 'RpcService extends JsonRpcConsumers implements ' . u
namespace Rpc\Consumers;
use Note\Target;
use Kiri\Rpc\Note\JsonRpc;
use Kiri\Annotation\Target;
use Kiri\Rpc\Annotation\JsonRpc;
use Http\Handler\Controller;
use Rpc\\' . ucfirst($name) . 'RpcInterface;
+7 -7
View File
@@ -66,11 +66,11 @@ namespace ' . $namespace . ';
$html .= $imports . PHP_EOL;
}
if (!str_contains($imports, 'Database\Note\Set')) {
$html .= 'use Database\Note\Set;' . PHP_EOL;
if (!str_contains($imports, 'Database\Annotation\Set')) {
$html .= 'use Database\Annotation\Set;' . PHP_EOL;
}
if (!str_contains($imports, 'Database\Note\Get')) {
$html .= 'use Database\Note\Get;' . PHP_EOL;
if (!str_contains($imports, 'Database\Annotation\Get')) {
$html .= 'use Database\Annotation\Get;' . PHP_EOL;
}
} catch (\Throwable $e) {
logger()->addError($e, 'throwable');
@@ -84,11 +84,11 @@ namespace ' . $namespace . ';
use Exception;
use Note\Target;
use Kiri\Annotation\Target;
use Kiri\Core\Json;
use Database\Connection;
use Database\Note\Get;
use Database\Note\Set;
use Database\Annotation\Get;
use Database\Annotation\Set;
use Database\Relation;
use Database\Model;
' . PHP_EOL;
+3 -3
View File
@@ -36,9 +36,9 @@ class GiiRpcClient extends GiiBase
namespace App\Client\Rpc;
use Note\Rpc\Consumer;
use Note\Rpc\RpcClient;
use Note\Target;
use Kiri\Annotation\Rpc\Consumer;
use Kiri\Annotation\Rpc\RpcClient;
use Kiri\Annotation\Target;
use Exception;
use Rpc\Client;
use Kiri\Core\Json;
+2 -2
View File
@@ -33,8 +33,8 @@ class GiiRpcService extends GiiBase
namespace App\Rpc;
use Note\Route\RpcProducer;
use Note\Target;
use Kiri\Annotation\Route\RpcProducer;
use Kiri\Annotation\Target;
use Exception;
use Http\Controller;
use Kiri\Core\Json;
+11 -1
View File
@@ -44,6 +44,17 @@ class Sender implements WebSocketInterface
}
/**
* @param $fd
* @param $reactor_id
* @return array|null
*/
public function connection_info($fd, $reactor_id = null): ?array
{
return $this->server->getClientInfo($fd, $reactor_id);
}
/**
* @param int $fd
* @param int $code
@@ -53,7 +64,6 @@ class Sender implements WebSocketInterface
public function disconnect(int $fd, int $code = SWOOLE_WEBSOCKET_CLOSE_NORMAL, string $reason = ''): bool
{
if ($this->isEstablished($fd)) {
// TODO: Implement disconnect() method.
return $this->server->disconnect($fd, $code, $reason);
}
return false;
+36 -10
View File
@@ -6,7 +6,7 @@ use Exception;
use Http\Handler\DataGrip;
use Http\Handler\Router;
use Kiri\Abstracts\AbstractServer;
use Note\Inject;
use Kiri\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Server\Contract\OnCloseInterface;
@@ -23,7 +23,7 @@ use Swoole\WebSocket\Server as WebSocketServer;
/**
* websocket server
*/
class Server extends AbstractServer implements OnHandshakeInterface, OnMessageInterface, OnCloseInterface
class Server extends AbstractServer
{
public Router $router;
@@ -36,10 +36,11 @@ class Server extends AbstractServer implements OnHandshakeInterface, OnMessageIn
/**
* @var WebSocketServer
* @var WebSocketInterface
*/
#[Inject(SwooleServerInterface::class)]
public WebSocketServer $server;
#[Inject(WebSocketInterface::class)]
public WebSocketInterface $server;
/**
@@ -116,8 +117,25 @@ class Server extends AbstractServer implements OnHandshakeInterface, OnMessageIn
$response->setStatusCode(101, 'connection success.');
$response->end();
}
if ($this->callback instanceof OnOpenInterface) {
$this->callback->onOpen($this->server, $request);
// if ($this->server instanceof \Swoole\Coroutine\Http\Server) {
// $response->upgrade();
// $this->deferOpen($request);
// while (true) {
// $receive = $response->recv();
// if ($receive === '' || $receive instanceof CloseFrame) {
// $response->close();
// if ($this->callback instanceof OnCloseInterface) {
// $this->callback->onClose($this->server, $response->fd);
// }
// break;
// }
// $this->callback->onMessage($this->server, $receive);
// }
// } else {
// $this->deferOpen($request);
// }
if ($response->isWritable()) {
$this->deferOpen($request);
}
} catch (\Throwable $throwable) {
$response->status(4000 + $throwable->getCode(), $throwable->getMessage());
@@ -126,14 +144,22 @@ class Server extends AbstractServer implements OnHandshakeInterface, OnMessageIn
}
private function deferOpen($request)
{
if ($this->callback instanceof OnOpenInterface) {
$this->callback->onOpen($request);
}
}
/**
* @param \Swoole\Server $server
* @param $server
* @param Frame $frame
*/
public function onMessage(\Swoole\Server $server, Frame $frame): void
public function onMessage($server, Frame $frame): void
{
if ($this->callback instanceof OnMessageInterface) {
$this->callback->onMessage($server, $frame);
$this->callback->onMessage($frame);
}
}
}