改名
This commit is contained in:
@@ -37,13 +37,6 @@ use Snowflake\Snowflake;
|
|||||||
{
|
{
|
||||||
// TODO: Implement setHandler() method.
|
// TODO: Implement setHandler() method.
|
||||||
$router = Snowflake::app()->getRouter();
|
$router = Snowflake::app()->getRouter();
|
||||||
$attribute = Snowflake::getDi()->getMethodAttribute($class::class, $method);
|
|
||||||
foreach ($attribute as $item) {
|
|
||||||
if ($item instanceof Route) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$item->execute($class, $method);
|
|
||||||
}
|
|
||||||
$router->addRoute($this->uri, [$class, $method], $this->method);
|
$router->addRoute($this->uri, [$class, $method], $this->method);
|
||||||
return $router;
|
return $router;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ use Annotation\Aspect;
|
|||||||
use Annotation\Route\RpcProducer;
|
use Annotation\Route\RpcProducer;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Exception;
|
use Exception;
|
||||||
use HttpServer\Abstracts\HttpService;
|
|
||||||
use HttpServer\Http\Request;
|
use HttpServer\Http\Request;
|
||||||
use JetBrains\PhpStorm\Pure;
|
use JetBrains\PhpStorm\Pure;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
|
use Server\Events\OnAfterWorkerStart;
|
||||||
|
use Snowflake\Events\EventProvider;
|
||||||
use Snowflake\Exception\NotFindClassException;
|
use Snowflake\Exception\NotFindClassException;
|
||||||
use Snowflake\IAspect;
|
use Snowflake\IAspect;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
@@ -21,7 +22,7 @@ use Snowflake\Snowflake;
|
|||||||
* Class Node
|
* Class Node
|
||||||
* @package Snowflake\Snowflake\Route
|
* @package Snowflake\Snowflake\Route
|
||||||
*/
|
*/
|
||||||
class Node extends HttpService
|
class Node
|
||||||
{
|
{
|
||||||
|
|
||||||
public string $path = '';
|
public string $path = '';
|
||||||
@@ -37,6 +38,8 @@ class Node extends HttpService
|
|||||||
|
|
||||||
private string $_dataType = '';
|
private string $_dataType = '';
|
||||||
|
|
||||||
|
private array|Closure|null $_handler = null;
|
||||||
|
|
||||||
public string $htmlSuffix = '.html';
|
public string $htmlSuffix = '.html';
|
||||||
public bool $enableHtmlSuffix = false;
|
public bool $enableHtmlSuffix = false;
|
||||||
public array $namespace = [];
|
public array $namespace = [];
|
||||||
@@ -59,6 +62,17 @@ class Node extends HttpService
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws NotFindClassException
|
||||||
|
* @throws ReflectionException
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$eventDispatcher = di(EventProvider::class);
|
||||||
|
$eventDispatcher->on(OnAfterWorkerStart::class, [$this, 'setParameters']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $data
|
* @param string $data
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@@ -90,7 +104,8 @@ class Node extends HttpService
|
|||||||
} else if ($handler != null && !is_callable($handler, true)) {
|
} else if ($handler != null && !is_callable($handler, true)) {
|
||||||
$this->_error = 'Controller is con\'t exec.';
|
$this->_error = 'Controller is con\'t exec.';
|
||||||
}
|
}
|
||||||
return $this->setParameters($handler);
|
$this->_handler = $handler;
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -176,19 +191,22 @@ class Node extends HttpService
|
|||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @throws NotFindClassException
|
* @throws NotFindClassException
|
||||||
*/
|
*/
|
||||||
public function setParameters($handler): static
|
public function setParameters(): static
|
||||||
{
|
{
|
||||||
$container = Snowflake::getDi();
|
$container = Snowflake::getDi();
|
||||||
if ($handler instanceof Closure) {
|
|
||||||
$this->_injectParameters = $container->resolveFunctionParameters($handler);
|
$dispatcher = $this->_handler;
|
||||||
|
unset($this->_handler);
|
||||||
|
if ($dispatcher instanceof Closure) {
|
||||||
|
$this->_injectParameters = $container->resolveFunctionParameters($dispatcher);
|
||||||
} else {
|
} else {
|
||||||
[$controller, $action] = $handler;
|
[$controller, $action] = $dispatcher;
|
||||||
if (is_object($controller)) {
|
if (is_object($controller)) {
|
||||||
$controller = get_class($controller);
|
$controller = get_class($controller);
|
||||||
}
|
}
|
||||||
$this->_injectParameters = $container->getMethodParameters($controller, $action);
|
$this->_injectParameters = $container->getMethodParameters($controller, $action);
|
||||||
}
|
}
|
||||||
return $this->injectMiddleware($handler);
|
return $this->injectMiddleware($dispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Server\Events;
|
||||||
|
|
||||||
|
class OnAfterWorkerStart
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ use Annotation\Inject;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Server\Constant;
|
use Server\Constant;
|
||||||
|
use Server\Events\OnAfterWorkerStart;
|
||||||
use Server\Events\OnWorkerError;
|
use Server\Events\OnWorkerError;
|
||||||
use Server\Events\OnWorkerExit;
|
use Server\Events\OnWorkerExit;
|
||||||
use Server\Events\OnWorkerStart;
|
use Server\Events\OnWorkerStart;
|
||||||
@@ -56,6 +57,8 @@ class OnServerWorker extends \Server\Abstracts\Server
|
|||||||
|
|
||||||
$this->workerInitExecutor($server, $annotation, $workerId);
|
$this->workerInitExecutor($server, $annotation, $workerId);
|
||||||
$this->interpretDirectory($annotation);
|
$this->interpretDirectory($annotation);
|
||||||
|
|
||||||
|
$this->eventDispatch->dispatch(new OnAfterWorkerStart());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user