- Added definition loading ordering
This commit is contained in:
		
							parent
							
								
									163df3f4ba
								
							
						
					
					
						commit
						4e28917b96
					
				| @ -1,7 +1,6 @@ | ||||
| <?php | ||||
| 
 | ||||
| use Ulmus\Container\AdapterProxy; | ||||
| use Psr\Container\ContainerInterface; | ||||
| use Ulmus\ConnectionAdapter; | ||||
| 
 | ||||
| use function DI\autowire, DI\create, DI\get, DI\add; | ||||
| @ -11,9 +10,8 @@ return [ | ||||
|         AdapterProxy::class, | ||||
|     ]), | ||||
| 
 | ||||
|     AdapterProxy::class => function (ContainerInterface $c) { | ||||
|     AdapterProxy::class => function (Psr\Container\ContainerInterface $c) { | ||||
|         return new AdapterProxy( | ||||
|             $c->get('lean:adapter.sqlite'), | ||||
|             $c->get(ConnectionAdapter::class), | ||||
|         ); | ||||
|     }, | ||||
|  | ||||
							
								
								
									
										31
									
								
								src/Lean.php
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								src/Lean.php
									
									
									
									
									
								
							| @ -22,13 +22,16 @@ class Lean | ||||
| 
 | ||||
|     protected function loadApplications() : void | ||||
|     { | ||||
|         $list = $this->container->get('config')['lean']['autoload'] ?? []; | ||||
|         $list = array_filter($this->container->get('config')['lean']['autoload'] ?? []); | ||||
| 
 | ||||
|         if (! $list ) { | ||||
|             throw new \Exception("You must provide at least one application to autoload within your config file ( 'lean' => 'autoload' => [] )"); | ||||
|         } | ||||
| 
 | ||||
|         foreach(array_filter($list) as $application) { | ||||
|         # Allows 'lean.default' and [ 'lean.default', 100 ] which allows ordering of apps loading.
 | ||||
|         usort($list, fn($e1, $e2) => ( is_array($e1) ? $e1[1] : 0 ) <=> ( is_array($e2) ? $e2[1] : 0 )); | ||||
| 
 | ||||
|         foreach(array_map(fn($item) => is_array($item) ? $item[0] : $item, $list) as $application) { | ||||
|             if ( $this->container->has($application) ) { | ||||
|                 $this->applications[] = ( new Application($application) )->fromArray($this->container->get($application)); | ||||
|             } | ||||
| @ -166,29 +169,23 @@ class Lean | ||||
|         $list = []; | ||||
| 
 | ||||
|         foreach(Composer::readComposerLock()['packages'] as $package) { | ||||
|             $order = $package['extra']['lean']['autoload']['order'] ?? 0; | ||||
| 
 | ||||
|             foreach($package['extra']['lean']['autoload']['definitions'] ?? [] as $autoload) { | ||||
|                 $list[] = static::pathFromPackage($package, $autoload); | ||||
|                 $list[] = [ static::pathFromPackage($package, $autoload), $order ]; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         foreach(Composer::readComposerJson()['extra']['lean']['autoload']['definitions'] ?? [] as $autoload) { | ||||
|             $list[] = getenv('PROJECT_PATH') . DIRECTORY_SEPARATOR . $autoload; | ||||
|             $order = $package['extra']['lean']['autoload']['order'] ?? 1000; | ||||
| 
 | ||||
|             $list[] = [ getenv('PROJECT_PATH') . DIRECTORY_SEPARATOR . $autoload, $order ]; | ||||
|         } | ||||
| 
 | ||||
|         return $list; | ||||
|     } | ||||
|         # Allows 'lean.default' and [ 'lean.default', 100 ] which allows ordering of apps loading.
 | ||||
|         usort($list, fn($e1, $e2) => $e1[1] <=>  $e2[1]); | ||||
| 
 | ||||
|     public static function autoloadDefinitionsFromComposerExtra() : array | ||||
|     { | ||||
|         $list = []; | ||||
| 
 | ||||
|         foreach(Composer::readComposerLock()['packages'] as $package) { | ||||
|             foreach($package['extra']['lean']['autoload']['definitions'] ?? [] as $autoload) { | ||||
|                 $list = array_replace($list, static::loadFromPackage($package, $autoload)); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return $list; | ||||
|         return array_column($list, 0); | ||||
|     } | ||||
| 
 | ||||
|     public static function autoloadConfigFromComposerExtra() : array | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user