- WIP on Lean's event definition
This commit is contained in:
parent
42f33d9f13
commit
156defddc9
@ -1,8 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Picea\Picea;
|
||||
use function DI\autowire, DI\create, DI\get;
|
||||
|
||||
use Lean\{ Lean, Routing, Event\RoutingCompileRoutes, Event\RoutingMapRoutes };
|
||||
use Mcnd\Event;
|
||||
use Taxus\Taxus;
|
||||
@ -11,6 +9,9 @@ use Notes\Route\Attribute\Method\Route;
|
||||
use Notes\Security\SecurityHandler;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
|
||||
use Ulmus\User\Entity\UserInterface;
|
||||
|
||||
use function DI\autowire, DI\create, DI\get;
|
||||
|
||||
return [
|
||||
Event\EventManager::class => autowire(Event\EventManager::class),
|
||||
@ -25,6 +26,7 @@ return [
|
||||
|
||||
Event\EventDefinition::class => function($c) {
|
||||
$extension = $c->has(\Picea\Extension\UrlExtension::class) ? $c->get(\Picea\Extension\UrlExtension::class) : null;
|
||||
$user = $c->get(UserInterface::class);
|
||||
|
||||
return new Event\EventDefinition([
|
||||
new class($extension) implements RoutingCompileRoutes {
|
||||
@ -40,7 +42,12 @@ return [
|
||||
}
|
||||
},
|
||||
|
||||
new class() implements RoutingMapRoutes {
|
||||
new class($user) implements RoutingMapRoutes {
|
||||
|
||||
public function __construct(
|
||||
protected UserInterface $user
|
||||
) {}
|
||||
|
||||
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route $attribute) : void
|
||||
{
|
||||
$class = $attribute->class;
|
||||
@ -54,7 +61,7 @@ return [
|
||||
$securityHandler = $container->get(SecurityHandler::class);
|
||||
|
||||
if ( $redirect = $securityHandler->verify($class, $method) ) {
|
||||
if ( empty($object->user) || ! $object->user->logged ) {
|
||||
if (! $this->user->loggedIn() ) {
|
||||
if ($container->has(Session::class)) {
|
||||
$container->get(Session::class)->set('redirectedFrom', (string)$request->getUri());
|
||||
}
|
||||
@ -65,7 +72,7 @@ return [
|
||||
}
|
||||
|
||||
if ( $securityHandler->isLocked($class, $method) && $container->has(Taxus::class)) {
|
||||
if ( $forbidden = $securityHandler->taxus($class, $method, $object->user ?? null) ) {
|
||||
if ( $forbidden = $securityHandler->taxus($class, $method, $this->user) ) {
|
||||
$routing->response = $forbidden;
|
||||
|
||||
return;
|
||||
|
@ -20,8 +20,8 @@ use function file_get_contents;
|
||||
#[Route(method: [ "GET", "POST" ])]
|
||||
trait ControllerTrait {
|
||||
|
||||
#[Inject]
|
||||
public \Notes\Breadcrumb\Breadcrumb $breadcrumb;
|
||||
##[Inject]
|
||||
# public \Notes\Breadcrumb\Breadcrumb $breadcrumb;
|
||||
|
||||
#[Inject]
|
||||
public Session $session;
|
||||
|
@ -6,6 +6,7 @@ use Lean\Routing;
|
||||
use Notes\Route\Attribute\Method\Route;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
|
||||
use Ulmus\User\Entity\UserInterface;
|
||||
|
||||
interface RoutingMapRoutes {
|
||||
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route $attribute) : void;
|
||||
|
Loading…
x
Reference in New Issue
Block a user