WIP on liteing the framework
This commit is contained in:
1 parent
bc55a2ab89
commit
9b795b857a
7 files changed
+36
-67
No files matched your search
@@ -13,8 +13,8 @@ use Psr\Http\Message\{ ServerRequestInterface, ResponseInterface };
|
||||
|
||||
use function file_get_contents;
|
||||
|
||||
#[Security(locked: true)]
|
||||
#[Route(method: [ "GET", "POST", "DELETE" ])]
|
||||
#[Security(locked: true, realm: "Protected Area")]
|
||||
#[Route(method: [ "GET", "POST" ])]
|
||||
trait ControllerTrait {
|
||||
public ? \Notes\Breadcrumb\Breadcrumb $breadcrumb;
|
||||
|
||||
|
||||
@@ -4,10 +4,16 @@ namespace Lean\Factory;
|
||||
|
||||
use Laminas\Diactoros\Response\{EmptyResponse, HtmlResponse, JsonResponse, RedirectResponse, TextResponse};
|
||||
use Lean\Response\{ DownloadResponse, ImageResponse, FileDownloadResponse, PdfResponse };
|
||||
use Laminas\Diactoros\Response;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class HttpFactory
|
||||
{
|
||||
public static function createResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface
|
||||
{
|
||||
return new Response($url, $code, $headers);
|
||||
}
|
||||
|
||||
public static function createRedirectResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface
|
||||
{
|
||||
return new RedirectResponse($url, $code, $headers);
|
||||
|
||||
+10
-34
@@ -2,9 +2,6 @@
|
||||
|
||||
namespace Lean;
|
||||
|
||||
use Notes\Annotation;
|
||||
use Taxus\Taxus;
|
||||
|
||||
use League\Route\RouteGroup,
|
||||
League\Route\Router;
|
||||
|
||||
@@ -14,54 +11,33 @@ use Psr\Http\Message\ServerRequestInterface,
|
||||
|
||||
use Notes\Route\RouteFetcher;
|
||||
|
||||
use Notes\Security\SecurityHandler;
|
||||
|
||||
use Notes\Tell\LanguageHandler;
|
||||
|
||||
use Picea\Picea,
|
||||
Picea\Extension\UrlExtension;
|
||||
|
||||
use Storage\Cookie,
|
||||
Storage\Session;
|
||||
|
||||
use Mcnd\Event\EventManager;
|
||||
|
||||
use function DI\autowire, DI\create;
|
||||
|
||||
class Routing {
|
||||
|
||||
public Annotation $selectedRoute;
|
||||
|
||||
public ResponseInterface $response;
|
||||
|
||||
public function __construct(
|
||||
public Session $session,
|
||||
public Cookie $cookie,
|
||||
public UrlExtension $extension,
|
||||
public Router $router,
|
||||
public RouteFetcher $fetcher,
|
||||
public SecurityHandler $security,
|
||||
public Taxus $taxus,
|
||||
public EventManager $eventManager,
|
||||
) { }
|
||||
|
||||
public function registerRoute(ContainerInterface $container, string $urlBase) {
|
||||
$this->router->group(rtrim($urlBase, "/"), function (RouteGroup $route) use ($container) {
|
||||
foreach($this->fetcher->compile() as $annotation) {
|
||||
$this->eventManager->execute(Event\RoutingCompileRoutes::class, $this, $annotation);
|
||||
foreach($this->fetcher->compile() as $attribute) {
|
||||
$this->eventManager->execute(Event\RoutingCompileRoutes::class, $this, $attribute);
|
||||
|
||||
/* @deprecated annotation->method will become standard when using native attributes */
|
||||
foreach((array) ( $annotation->method ?? $annotation->methods ) as $method) {
|
||||
# Mapping every URLs from annotations in searched folders (Api, Controller, etc...)
|
||||
$route->map(strtoupper($method), $annotation->getRoute(), function (ServerRequestInterface $request, array $arguments) use (
|
||||
$container, $route, $annotation
|
||||
) : ResponseInterface
|
||||
{
|
||||
$class = $annotation->class;
|
||||
$method = $annotation->classMethod;
|
||||
# Mapping every URLs from attributes in searched folders (Api, Controller, etc...)
|
||||
foreach((array) $attribute->method as $method) {
|
||||
$route->map(strtoupper($method), $attribute->getRoute(), function (ServerRequestInterface $request, array $arguments) use (
|
||||
$container, $route, $attribute
|
||||
) : ResponseInterface {
|
||||
$class = $attribute->class;
|
||||
$method = $attribute->classMethod;
|
||||
$object = $container->get($class);
|
||||
|
||||
$this->eventManager->execute(Event\RoutingMapRoutes::class, $this, $container, $request, $annotation);
|
||||
$this->eventManager->execute(Event\RoutingMapRoutes::class, $this, $container, $request, $attribute);
|
||||
|
||||
$container->set(ServerRequestInterface::class, $request);
|
||||
|
||||
|
||||
Reference in new issue
Block a user