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