eee
This commit is contained in:
+42
-46
@@ -82,16 +82,16 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
|
||||
|
||||
public function clear(): void
|
||||
{
|
||||
$this->_item = [];
|
||||
$this->dump = [];
|
||||
$this->groupTack = [];
|
||||
$this->methods = [];
|
||||
$this->_item = [];
|
||||
$this->dump = [];
|
||||
$this->groupTack = [];
|
||||
$this->methods = [];
|
||||
$this->httpHandler = [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $method
|
||||
* @param HttpRequestHandler $handler
|
||||
* @return void
|
||||
*/
|
||||
@@ -120,8 +120,8 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
|
||||
|
||||
|
||||
/**
|
||||
* @param array $method
|
||||
* @param string $route
|
||||
* @param array $method
|
||||
* @param string $route
|
||||
* @param string|array|Closure $closure
|
||||
*/
|
||||
public function addRoute(array $method, string $route, string|array|Closure $closure): void
|
||||
@@ -164,7 +164,7 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
|
||||
$array[] = [
|
||||
'path' => $path,
|
||||
'method' => $method,
|
||||
'handler' => $controller
|
||||
'handler' => $controller,
|
||||
];
|
||||
}
|
||||
return $array;
|
||||
@@ -172,7 +172,7 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
|
||||
|
||||
|
||||
/**
|
||||
* @param string|array $closure
|
||||
* @param string|array $closure
|
||||
* @param ControllerInterpreter $interpreter
|
||||
* @return Handler
|
||||
* @throws
|
||||
@@ -184,7 +184,7 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
|
||||
if (is_string($closure[0])) {
|
||||
$closure[0] = $container->get($closure[0]);
|
||||
}
|
||||
$handler = $interpreter->addRouteByString(... $closure);
|
||||
$handler = $interpreter->addRouteByString(... $closure);
|
||||
$sourceFile = Router::getCurrentSourceFile();
|
||||
if ($sourceFile !== null) {
|
||||
$handler->setSourceFile($sourceFile);
|
||||
@@ -196,8 +196,8 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
|
||||
$closure .= '@';
|
||||
}
|
||||
[$className, $method] = explode('@', $closure);
|
||||
$class = $container->get($this->resetName($className));
|
||||
$handler = $interpreter->addRouteByString($class, $method);
|
||||
$class = $container->get($this->resetName($className));
|
||||
$handler = $interpreter->addRouteByString($class, $method);
|
||||
$sourceFile = Router::getCurrentSourceFile();
|
||||
if ($sourceFile !== null) {
|
||||
$handler->setSourceFile($sourceFile);
|
||||
@@ -222,8 +222,8 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
|
||||
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param string $method
|
||||
* @param string $path
|
||||
* @param string $method
|
||||
* @param Handler $handler
|
||||
* @return void
|
||||
* @throws
|
||||
@@ -244,7 +244,7 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
|
||||
|
||||
public function exportArtifact(): array
|
||||
{
|
||||
$entries = [];
|
||||
$entries = [];
|
||||
$hasClosureRoutes = false;
|
||||
|
||||
foreach ($this->methods as $methodPath => $handler) {
|
||||
@@ -254,28 +254,28 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
|
||||
}
|
||||
|
||||
[$requestMethod, $path] = explode('_', $methodPath, 2);
|
||||
$class = $handler instanceof Handler ? $handler->getClass() : $handler->class;
|
||||
$method = $handler instanceof Handler ? $handler->getMethod() : $handler->method;
|
||||
$class = $handler instanceof Handler ? $handler->getClass() : $handler->class;
|
||||
$method = $handler instanceof Handler ? $handler->getMethod() : $handler->method;
|
||||
$middlewares = $handler instanceof Handler ? $handler->getMiddlewares() : $handler->middlewares;
|
||||
$sourceFile = $handler instanceof Handler ? $handler->getSourceFile() : $handler->sourceFile;
|
||||
$sourceKind = $handler instanceof Handler ? $handler->getSourceKind() : $handler->sourceKind;
|
||||
$deferred = $handler instanceof Handler ? $this->serializeDeferred($handler->getDeferred()) : ($handler->deferred ?? []);
|
||||
$sourceFile = $handler instanceof Handler ? $handler->getSourceFile() : $handler->sourceFile;
|
||||
$sourceKind = $handler instanceof Handler ? $handler->getSourceKind() : $handler->sourceKind;
|
||||
$deferred = $handler instanceof Handler ? $this->serializeDeferred($handler->getDeferred()) : ($handler->deferred ?? []);
|
||||
|
||||
$entries[] = [
|
||||
'request_method' => $requestMethod,
|
||||
'path' => $path,
|
||||
'class' => $class,
|
||||
'method' => $method,
|
||||
'middlewares' => $middlewares,
|
||||
'source_file' => $sourceFile,
|
||||
'source_kind' => $sourceKind,
|
||||
'deferred' => $deferred,
|
||||
'path' => $path,
|
||||
'class' => $class,
|
||||
'method' => $method,
|
||||
'middlewares' => $middlewares,
|
||||
'source_file' => $sourceFile,
|
||||
'source_kind' => $sourceKind,
|
||||
'deferred' => $deferred,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'has_closure_routes' => $hasClosureRoutes,
|
||||
'entries' => $entries,
|
||||
'entries' => $entries,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -302,25 +302,21 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
|
||||
continue;
|
||||
}
|
||||
|
||||
$class = $entry['class'] ?? null;
|
||||
$method = $entry['method'] ?? null;
|
||||
$class = $entry['class'] ?? null;
|
||||
$method = $entry['method'] ?? null;
|
||||
$requestMethod = $entry['request_method'] ?? null;
|
||||
$path = $entry['path'] ?? null;
|
||||
$path = $entry['path'] ?? null;
|
||||
|
||||
if (!is_string($class) || !is_string($method) || !is_string($requestMethod) || !is_string($path)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->methods[$requestMethod . '_' . $path] = new RouteEntry(
|
||||
requestMethod: $requestMethod,
|
||||
path: $path,
|
||||
class: $class,
|
||||
method: $method,
|
||||
middlewares: is_array($entry['middlewares'] ?? null) ? $entry['middlewares'] : [],
|
||||
sourceFile: is_string($sourceFile) ? $this->normalizePath($sourceFile) : null,
|
||||
sourceKind: is_string($entry['source_kind'] ?? null) ? $entry['source_kind'] : 'attribute',
|
||||
deferred: is_array($entry['deferred'] ?? null) ? $entry['deferred'] : [],
|
||||
);
|
||||
$middlewares = is_array($entry['middlewares'] ?? null) ? $entry['middlewares'] : [];
|
||||
$sourceFile = is_string($sourceFile) ? $this->normalizePath($sourceFile) : null;
|
||||
$sourceKind = is_string($entry['source_kind'] ?? null) ? $entry['source_kind'] : 'attribute';
|
||||
$deferred = is_array($entry['deferred'] ?? null) ? $entry['deferred'] : [];
|
||||
|
||||
$this->methods[$requestMethod . '_' . $path] = new RouteEntry(requestMethod: $requestMethod, path: $path, class: $class, method: $method, middlewares: $middlewares, sourceFile: $sourceFile, sourceKind: $sourceKind, deferred: $deferred);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -348,7 +344,7 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
|
||||
|
||||
|
||||
/**
|
||||
* @param array $response
|
||||
* @param array $response
|
||||
* @param string $class
|
||||
* @param string $method
|
||||
* @return array
|
||||
@@ -379,8 +375,8 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
|
||||
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string $method
|
||||
* @param array $response
|
||||
* @param array $middlewares
|
||||
* @return Defer[]
|
||||
*/
|
||||
|
||||
@@ -499,7 +495,7 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
|
||||
{
|
||||
if ($method instanceof RouteEntry) {
|
||||
$controller = \Kiri::getDi()->get($method->class);
|
||||
$handler = di(ControllerInterpreter::class)->addRouteByString($controller, $method->method);
|
||||
$handler = di(ControllerInterpreter::class)->addRouteByString($controller, $method->method);
|
||||
$handler->setRequestMethod($method->requestMethod);
|
||||
$handler->setMiddlewares($method->middlewares);
|
||||
$handler->setSourceFile($method->sourceFile);
|
||||
@@ -514,7 +510,7 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
|
||||
}
|
||||
|
||||
$requestHandler = new HttpRequestHandler($middlewares, $method);
|
||||
$validator = Middleware::getValidator($method->getClass(), $method->getMethod());
|
||||
$validator = Middleware::getValidator($method->getClass(), $method->getMethod());
|
||||
if ($validator !== null) {
|
||||
$requestHandler->withValidatorMiddleware(new ValidatorMiddleware(di(\Psr\Http\Message\ResponseInterface::class), $method->getClass(), $method->getMethod()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user