- Added AdapterProxy autoload in ORM
This commit is contained in:
		
							parent
							
								
									69382f912b
								
							
						
					
					
						commit
						42f33d9f13
					
				| @ -1,7 +1,5 @@ | |||||||
| <?php | <?php | ||||||
| 
 | 
 | ||||||
| use Lean\Factory\HttpFactory; |  | ||||||
| 
 |  | ||||||
| use Ulmus\User\{Entity, | use Ulmus\User\{Entity, | ||||||
|     Lib\Authenticate, |     Lib\Authenticate, | ||||||
|     Lib\Authorize, |     Lib\Authorize, | ||||||
| @ -13,7 +11,7 @@ use Picea\Picea; | |||||||
| 
 | 
 | ||||||
| use Storage\{ Cookie, Session }; | use Storage\{ Cookie, Session }; | ||||||
| 
 | 
 | ||||||
| use function DI\{get, autowire, create}; | use function DI\{get, create}; | ||||||
| 
 | 
 | ||||||
| return [ | return [ | ||||||
|     Authenticate::class => create(Authenticate::class)->constructor(get(Entity\UserInterface::class), get(Session::class), get(Cookie::class), get('authentication.method')), |     Authenticate::class => create(Authenticate::class)->constructor(get(Entity\UserInterface::class), get(Session::class), get(Cookie::class), get('authentication.method')), | ||||||
| @ -29,17 +27,17 @@ return [ | |||||||
|     'authentication.method' => null, |     'authentication.method' => null, | ||||||
| 
 | 
 | ||||||
|     'authorize.error' => function($c) { |     'authorize.error' => function($c) { | ||||||
|         return function(array $errorData) { |         return function(array $errorData) use ($c) { | ||||||
|             return HttpFactory::createJsonResponse($errorData + [ |             return $c->get(\Lean\Factory\HttpFactoryInterface::class)::createJsonResponse($errorData + [ | ||||||
|                 'api.error' => "Authorization failed", |                 'api.error' => "Authorization failed", | ||||||
|                 'api.datetime' => (new \DateTime)->format(\DateTime::ISO8601), |                 'api.datetime' => (new \DateTime)->format(\DateTime::ATOM), | ||||||
|             ], 403); |             ], 403); | ||||||
|         }; |         }; | ||||||
|     }, |     }, | ||||||
| 
 | 
 | ||||||
|     'authentication.error' => function($c, Picea $picea) { |     'authentication.error' => function($c, Picea $picea) { | ||||||
|         return function($message) use ($picea) { |         return function($message) use ($picea, $c) { | ||||||
|             return HttpFactory::createHtmlResponse($picea->renderHtml('lean/error/500', [ |             return $c->get(\Lean\Factory\HttpFactoryInterface::class)::createHtmlResponse($picea->renderHtml('lean/error/500', [ | ||||||
|                 'title' => "Authentication failed", |                 'title' => "Authentication failed", | ||||||
|                 'subtitle' => "", |                 'subtitle' => "", | ||||||
|                 'message' => $message, |                 'message' => $message, | ||||||
|  | |||||||
| @ -64,8 +64,8 @@ return [ | |||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
| 
 | 
 | ||||||
|                         if ( $securityHandler->isLocked($class, $method) && $container->has(Taxus::class) && $container->has(SecurityHandler::class) ) { |                         if ( $securityHandler->isLocked($class, $method) && $container->has(Taxus::class)) { | ||||||
|                             if ( $forbidden = $container->get(SecurityHandler::class)->taxus($class, $method, $object->user ?? null) ) { |                             if ( $forbidden = $securityHandler->taxus($class, $method, $object->user ?? null) ) { | ||||||
|                                 $routing->response = $forbidden; |                                 $routing->response = $forbidden; | ||||||
| 
 | 
 | ||||||
|                                 return; |                                 return; | ||||||
|  | |||||||
| @ -11,8 +11,12 @@ return [ | |||||||
|     ]), |     ]), | ||||||
| 
 | 
 | ||||||
|     AdapterProxy::class => function (Psr\Container\ContainerInterface $c) { |     AdapterProxy::class => function (Psr\Container\ContainerInterface $c) { | ||||||
|         return new AdapterProxy( |         $proxy = new AdapterProxy(); | ||||||
|             $c->get(ConnectionAdapter::class), |          | ||||||
|         ); |         $autoload = $c->get(\Lean\Lean::class)->getConnectionAdapters(); | ||||||
|  | 
 | ||||||
|  |         $proxy->push($autoload); | ||||||
|  | 
 | ||||||
|  |         return $proxy; | ||||||
|     }, |     }, | ||||||
| ]; | ]; | ||||||
|  | |||||||
| @ -66,20 +66,14 @@ return [ | |||||||
|         'routes' => [], |         'routes' => [], | ||||||
| 
 | 
 | ||||||
|         'cronard' => [], |         'cronard' => [], | ||||||
| 
 |  | ||||||
|         'taxus' => [ |  | ||||||
|             'is_dev' => [ ' dev' => "Is a developper of this application or has the same rights" ], |  | ||||||
|             'is_admin' => [ 'admin' => "Can manage almost everything in this application."], |  | ||||||
|             'is_moderator' => [ 'moderator' => "Can moderate this application."], |  | ||||||
|             'is_user' => [ 'user' => "Is an authenticated user."], |  | ||||||
|             'is_anonymous' => [ 'anonymous' => "Is an anonymous user."], |  | ||||||
|         ], |  | ||||||
|     ], |     ], | ||||||
| 
 | 
 | ||||||
|     'lean.autoload' => add([ |     'lean.autoload' => add([ | ||||||
|         Lean::class, |         Lean::class, | ||||||
|     ]), |     ]), | ||||||
| 
 | 
 | ||||||
|  |     \Lean\Factory\HttpFactoryInterface::class => autowire(\Lean\Factory\HttpFactory::class), | ||||||
|  | 
 | ||||||
|     Lean::class => autowire(Lean::class), |     Lean::class => autowire(Lean::class), | ||||||
| 
 | 
 | ||||||
|     JavascriptMiddleware::class => create(JavascriptMiddleware::class), |     JavascriptMiddleware::class => create(JavascriptMiddleware::class), | ||||||
|  | |||||||
| @ -22,6 +22,8 @@ class Application | |||||||
| 
 | 
 | ||||||
|     public array $entities; |     public array $entities; | ||||||
| 
 | 
 | ||||||
|  |     public array $connectionAdapters; | ||||||
|  | 
 | ||||||
|     public array $events; |     public array $events; | ||||||
| 
 | 
 | ||||||
|     public array $tellJson; |     public array $tellJson; | ||||||
| @ -68,6 +70,7 @@ class Application | |||||||
|         if (is_array($ulmus = $this->data['ulmus'] ?? false)) { |         if (is_array($ulmus = $this->data['ulmus'] ?? false)) { | ||||||
|             if ($ulmus['entities'] ?? false) { |             if ($ulmus['entities'] ?? false) { | ||||||
|                 $this->entities = $ulmus['entities']; |                 $this->entities = $ulmus['entities']; | ||||||
|  |                 $this->connectionAdapters = $ulmus['adapters'] ?? []; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -5,6 +5,7 @@ namespace Lean; | |||||||
| use League\Route\Strategy; | use League\Route\Strategy; | ||||||
| 
 | 
 | ||||||
| use League\Route\Http\Exception\NotFoundException; | use League\Route\Http\Exception\NotFoundException; | ||||||
|  | use Lean\Factory\HttpFactoryInterface; | ||||||
| use Picea\Asset\Asset; | use Picea\Asset\Asset; | ||||||
| use Psr\Container\ContainerInterface; | use Psr\Container\ContainerInterface; | ||||||
| use Psr\Http\Message\ResponseInterface; | use Psr\Http\Message\ResponseInterface; | ||||||
| @ -25,15 +26,17 @@ class ApplicationStrategy extends Strategy\ApplicationStrategy { | |||||||
|     public function __construct( |     public function __construct( | ||||||
|         protected Picea $picea, |         protected Picea $picea, | ||||||
|         protected ContainerInterface $di, |         protected ContainerInterface $di, | ||||||
|  |         protected HttpFactoryInterface $httpFactory, | ||||||
|     ) {} |     ) {} | ||||||
| 
 | 
 | ||||||
|     public function getNotFoundDecorator(NotFoundException $exception): MiddlewareInterface |     public function getNotFoundDecorator(NotFoundException $exception): MiddlewareInterface | ||||||
|     { |     { | ||||||
|         return new class($this->picea, $this->di) implements MiddlewareInterface { |         return new class($this->picea, $this->di, $this->httpFactory) implements MiddlewareInterface { | ||||||
| 
 | 
 | ||||||
|             public function __construct( |             public function __construct( | ||||||
|                 protected Picea $picea, |                 protected Picea $picea, | ||||||
|                 protected ContainerInterface $di, |                 protected ContainerInterface $di, | ||||||
|  |                 protected HttpFactoryInterface $httpFactory, | ||||||
|             ) { } |             ) { } | ||||||
| 
 | 
 | ||||||
|             public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |             public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||||||
| @ -58,7 +61,7 @@ class ApplicationStrategy extends Strategy\ApplicationStrategy { | |||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 return new \Laminas\Diactoros\Response\HtmlResponse($this->picea->renderHtml("lean/error/404", [], $this), 404); |                 return $this->httpFactory->createHtmlResponse($this->picea->renderHtml("lean/error/404", [], $this), 404); | ||||||
|             } |             } | ||||||
|         }; |         }; | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -147,13 +147,15 @@ trait ControllerTrait { | |||||||
|     #[Ignore]
 |     #[Ignore]
 | ||||||
|     public function renderCLI(ServerRequestInterface $request, mixed $data) : ResponseInterface |     public function renderCLI(ServerRequestInterface $request, mixed $data) : ResponseInterface | ||||||
|     { |     { | ||||||
|         if ($data instanceof \JsonSerializable ) { |         if (! $data instanceof \Stringable) { | ||||||
|             return $this->renderJson( |             if ($data instanceof \JsonSerializable) { | ||||||
|                 $data |                 return $this->renderJson( | ||||||
|             ); |                     $data | ||||||
|         } |                 ); | ||||||
|         elseif ( is_array($data) ) { |             } | ||||||
|             var_export($data); |             elseif (is_iterable($data) || is_object($data)) { | ||||||
|  |                 return $this->renderText(var_export($data, true)); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return $this->renderText( |         return $this->renderText( | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ use Lean\Response\{ DownloadResponse, ImageResponse, FileDownloadResponse, PdfRe | |||||||
| use Laminas\Diactoros\Response; | use Laminas\Diactoros\Response; | ||||||
| use Psr\Http\Message\ResponseInterface; | use Psr\Http\Message\ResponseInterface; | ||||||
| 
 | 
 | ||||||
| class HttpFactory | class HttpFactory implements HttpFactoryInterface | ||||||
| { | { | ||||||
|     public static function createResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface |     public static function createResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface | ||||||
|     { |     { | ||||||
|  | |||||||
							
								
								
									
										22
									
								
								src/Factory/HttpFactoryInterface.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/Factory/HttpFactoryInterface.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | |||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | 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; | ||||||
|  | 
 | ||||||
|  | interface HttpFactoryInterface | ||||||
|  | { | ||||||
|  |     public static function createResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface; | ||||||
|  |     public static function createRedirectResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface; | ||||||
|  |     public static function createHtmlResponse(string $html, int $code = 200, array $headers = []) : ResponseInterface; | ||||||
|  |     public static function createTextResponse(string $text, int $code = 200, array $headers = []) : ResponseInterface; | ||||||
|  |     public static function createJsonResponse(mixed $data, int $code = 200, array $headers = []) : ResponseInterface; | ||||||
|  |     public static function createEmptyResponse(int $code = 204, array $headers = []) : ResponseInterface; | ||||||
|  |     public static function createPdfResponse(\Stringable|string $binary, int $code = 200, array $headers = []) : ResponseInterface; | ||||||
|  |     public static function createDownloadableResponse(string $data, string $filename, int $code = 200, array $headers = []) : ResponseInterface; | ||||||
|  |     public static function createImageResponse(string $data, int $code = 200, array $headers = []) : ResponseInterface; | ||||||
|  |     public static function createFileDownloadResponse(string $path, int $code = 200, array $headers = []) : ResponseInterface; | ||||||
|  | } | ||||||
| @ -73,7 +73,9 @@ class Kernel { | |||||||
|                 $path = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . getenv($envkey); |                 $path = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . getenv($envkey); | ||||||
| 
 | 
 | ||||||
|                 if (getenv('DEBUG') && ! file_exists($path)) { |                 if (getenv('DEBUG') && ! file_exists($path)) { | ||||||
|                     mkdir($path, 0755, true); |                     if (false === mkdir($path, 0755, true)) { | ||||||
|  |                         throw new \Exception(sprintf("Folder '%s' could not be created", $path)); | ||||||
|  |                     } | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 static::putenv($name, realpath($path)); |                 static::putenv($name, realpath($path)); | ||||||
| @ -155,6 +157,7 @@ class Kernel { | |||||||
| 
 | 
 | ||||||
|         # Must be removed from KERNEL !
 |         # Must be removed from KERNEL !
 | ||||||
|         $this->container->has('ulmus.caching') and ( Ulmus::$cache = $this->container->get('ulmus.caching') ); |         $this->container->has('ulmus.caching') and ( Ulmus::$cache = $this->container->get('ulmus.caching') ); | ||||||
|  |         # $this->container->has(AdapterProxy::class) and ( $ )
 | ||||||
| 
 | 
 | ||||||
|         return $this; |         return $this; | ||||||
|     } |     } | ||||||
|  | |||||||
							
								
								
									
										25
									
								
								src/Lean.php
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								src/Lean.php
									
									
									
									
									
								
							| @ -77,37 +77,42 @@ class Lean | |||||||
| 
 | 
 | ||||||
|     public function getRoutable() : array |     public function getRoutable() : array | ||||||
|     { |     { | ||||||
|         return array_merge(...array_map(fn($app) => $app->routes ?? [], $this->applications)); |         return array_merge(...array_map(fn(Application $app) => $app->routes ?? [], $this->applications)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function getCronard() : array |     public function getCronard() : array | ||||||
|     { |     { | ||||||
|         return array_merge(...array_map(fn($app) => $app->cronard ?? [], $this->applications)); |         return array_merge(...array_map(fn(Application $app) => $app->cronard ?? [], $this->applications)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function getCLI() : array |     public function getCLI() : array | ||||||
|     { |     { | ||||||
|         return array_merge(...array_map(fn($app) => $app->cli ?? [], $this->applications)); |         return array_merge(...array_map(fn(Application $app) => $app->cli ?? [], $this->applications)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function getEvents() : array |     public function getEvents() : array | ||||||
|     { |     { | ||||||
|         return array_merge(...array_map(fn($app) => $app->events ?? [], $this->applications)); |         return array_merge(...array_map(fn(Application $app) => $app->events ?? [], $this->applications)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function getTaxusPrivileges() : array |     public function getTaxusPrivileges() : array | ||||||
|     { |     { | ||||||
|         return array_merge(...array_map(fn($app) => $app->taxus ?? [], $this->applications)); |         return array_merge(...array_map(fn(Application $app) => $app->taxus ?? [], $this->applications)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function getEntities() : array |     public function getEntities() : array | ||||||
|     { |     { | ||||||
|         return array_merge(...array_map(fn($app) => $app->entities ?? [], $this->applications)); |         return array_merge(...array_map(fn(Application $app) => $app->entities ?? [], $this->applications)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function getConnectionAdapters() : array | ||||||
|  |     { | ||||||
|  |         return array_merge(...array_map(fn(Application $app) => $app->connectionAdapters ?? [], $this->applications)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function getViewPaths() : array |     public function getViewPaths() : array | ||||||
|     { |     { | ||||||
|         $list = array_merge(...array_map(fn($app) => $app->views ?? [], $this->applications)); |         $list = array_merge(...array_map(fn(Application $app) => $app->views ?? [], $this->applications)); | ||||||
| 
 | 
 | ||||||
|         $this->verifyPathList($list); |         $this->verifyPathList($list); | ||||||
| 
 | 
 | ||||||
| @ -118,7 +123,7 @@ class Lean | |||||||
| 
 | 
 | ||||||
|     public function getAssetPaths() : array |     public function getAssetPaths() : array | ||||||
|     { |     { | ||||||
|         $list = array_merge(...array_map(fn($app) => $app->piceaAssets ?? [], $this->applications)); |         $list = array_merge(...array_map(fn(Application $app) => $app->piceaAssets ?? [], $this->applications)); | ||||||
| 
 | 
 | ||||||
|         $this->verifyPathList($list); |         $this->verifyPathList($list); | ||||||
| 
 | 
 | ||||||
| @ -140,11 +145,11 @@ class Lean | |||||||
|     { |     { | ||||||
|         switch($reader) { |         switch($reader) { | ||||||
|             case "php": |             case "php": | ||||||
|                 $list = array_merge(...array_map(fn($app) => $app->tellPhp ?? [], $this->applications)); |                 $list = array_merge(...array_map(fn(Application $app) => $app->tellPhp ?? [], $this->applications)); | ||||||
|                 break; |                 break; | ||||||
| 
 | 
 | ||||||
|             case "json": |             case "json": | ||||||
|                 $list = array_merge(...array_map(fn($app) => $app->tellJson ?? [], $this->applications)); |                 $list = array_merge(...array_map(fn(Application $app) => $app->tellJson ?? [], $this->applications)); | ||||||
|                 break; |                 break; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user