Skip to content

Instantly share code, notes, and snippets.

@n1215
Created May 31, 2017 12:44
Show Gist options
  • Save n1215/967dcde1b20a2506417268e483869ec7 to your computer and use it in GitHub Desktop.
Save n1215/967dcde1b20a2506417268e483869ec7 to your computer and use it in GitHub Desktop.
<?php
interface RequestMatcherInterface
{
match(RequestInterface $request) : RequestMatchResultInterface
}
interface RequestMatchResultInterface
{
public function getRequest(): ServerRequestInterface;
public function getMatcher(): RequestMatcherInterface;
public function getParams(): array;
public function getParam($key, $default = null): mixed;
public function isSuccess(): bool;
}
interface RouterInterface
{
public function match(RequestInterface $request) : RouterMatchResultInterface
}
interface RouteInterface
{
public function getName(): string;
pulblic function getMatcher(): RequestMatcherInterface;
public function getHandlerKey(): DelegateInterface|callable|string;
public function getMiddlewareKeys(): MiddlewareInterface[]|callable[]|string;
}
interface RouteMatchResultInterface extends RequestMatchResultInterface
{
public function getRoute(): RouteInterface|null;
}
class RouterApplication implements DelegateInterface
{
public function __construct(RouterInterface $router, Jugoya $jugoya)
{
$this->router = $router;
$this->jugoya = $jugoya;
}
public function process(Request $request)
{
$result = $this->router->match($request);
if($result->isFailure()) {
return $errorResponse;
}
$request->setAttirbute('hogehoge', $result->getParams());
$app = $this->jugoya->build($result->getHandlerKey(), $result->getMiddlewareKeys());
return $app->process($request);
}
}
$routeCollection = new RouteMap();
$routeCollection->addRoute(Get('/test/get/'), $coreDelegateKey, $routeMiddlewareKeys);
$routeCollection->addRoute(Get('/test/get/'), $coreDelegateKey, $routeMiddlewareKeys);
$routeCollection->addRoute(Get('/test/get/'), $coreDelegateKey, $routeMiddlewareKeys);
$container = new Container();
$appBuilder = Jugoya::fromContainer($container);
$coreApp = new RouterApplication(new Router($routeCollection), $appBuilder);
$holeApp = $appBuilder->build($coreApp, [
AppMiddleware::class,
]);
$response = $holeApp->process(ServerRequestFactory::fromGlobals());
interface RouteRegistrarInterface
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment