- Added the application feature - a big reason why Lean was created in the first place.
- Began moving some repetitive parts from projects to projects into lean
This commit is contained in:
1 parent
4bd68a74f8
commit
bdb9f7f732
13 files changed
+571
-2
No files matched your search
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
use function DI\autowire, DI\create, DI\get;
|
||||
|
||||
use League\Route\Strategy\ApplicationStrategy,
|
||||
League\Route\Http\Exception\NotFoundException,
|
||||
League\Route\Router;
|
||||
|
||||
use Psr\Http\Message\ResponseFactoryInterface,
|
||||
Psr\Container\ContainerInterface,
|
||||
Psr\Http\Message\ResponseInterface,
|
||||
Psr\Http\Message\ServerRequestInterface,
|
||||
Psr\Http\Server\MiddlewareInterface,
|
||||
Psr\Http\Server\RequestHandlerInterface;
|
||||
|
||||
use TheBugs\JavascriptMiddleware;
|
||||
|
||||
use Cronard\CronardMiddleware;
|
||||
|
||||
use Tuupola\Middleware\HttpBasicAuthentication;
|
||||
|
||||
use Notes\Route\RouteFetcher;
|
||||
|
||||
use Storage\SessionMiddleware;
|
||||
|
||||
return [
|
||||
Lean\Routing::class => autowire(Lean\Routing::class),
|
||||
|
||||
RouteFetcher::class => function($c) {
|
||||
$fetcher = new RouteFetcher();
|
||||
|
||||
$fetcher->setFolderList(array_map(function($item) {
|
||||
return getenv("PROJECT_PATH") . $item;
|
||||
}, $c->get(Lean\Lean::class)->getRoutable()));
|
||||
|
||||
return $fetcher;
|
||||
},
|
||||
|
||||
ApplicationStrategy::class => function($c) {
|
||||
return new class($c->get(Picea\Picea::class)) extends ApplicationStrategy {
|
||||
|
||||
public Picea\Picea $picea;
|
||||
|
||||
public function __construct(Picea\Picea $picea) {
|
||||
$this->picea = $picea;
|
||||
}
|
||||
|
||||
public function getNotFoundDecorator(NotFoundException $exception): MiddlewareInterface
|
||||
{
|
||||
return new class($this->picea) implements MiddlewareInterface {
|
||||
|
||||
protected Picea\Picea $picea;
|
||||
|
||||
public function __construct(Picea\Picea $picea) {
|
||||
$this->picea = $picea;
|
||||
}
|
||||
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
return new Zend\Diactoros\Response\HtmlResponse($this->picea->renderHtml("lean/error/404", [], $this), 404);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
},
|
||||
|
||||
'routes.list' => function($c) {
|
||||
return function (ContainerInterface $container) {
|
||||
$router = $container->get(Router::class);
|
||||
|
||||
foreach([ "errorHandler", "dump", SessionMiddleware::class, CronardMiddleware::class, HttpBasicAuthentication::class, JavascriptMiddleware::class ] as $middleware) {
|
||||
if ( $container->has($middleware) ) {
|
||||
$router->middleware($container->get($middleware));
|
||||
}
|
||||
}
|
||||
|
||||
$routing = $container->get(Lean\Routing::class);
|
||||
|
||||
$routing->registerRoute($container, getenv('URL_BASE'));
|
||||
|
||||
return $router;
|
||||
};
|
||||
},
|
||||
];
|
||||
Reference in new issue
Block a user