Beispiel #1
0
 /**
  * Registers a Service Provider to be loaded when the framework boots
  * 
  * If a service provider depends on other services that have not been registered
  * yet, it may be queued, rather than registered.  Once all services it relies on
  * have been registered, it will be registered.
  * 
  * @param  class<ServiceProvider>  $service  The Service Provider to register
  */
 public function register($class_name)
 {
     $class = new ReflectionClass($class_name);
     if (!$class->implementsInterface(ServiceProvider::class)) {
         throw new InvalidArgumentException("[{$class_name}] is not a service provider");
     }
     if ($class->hasConstant('requires')) {
         $requirements = array_flip($class->getConstant('requires'));
         foreach ($this->services as $service_name => $service) {
             if (array_key_exists($service_name, $requirements)) {
                 unset($requirements[$service_name]);
             }
         }
         if (count($requirements) !== 0) {
             $this->queue[$class_name] = array_flip($requirements);
             return;
         }
     }
     $service = $this->ioc->make($class_name);
     $service->register();
     if (!$class->hasConstant('provides')) {
         $this->services[] = $service;
     } else {
         $provides = $class->getConstant('provides');
         $this->services[$provides] = $service;
         foreach ($this->queue as $queued_name => &$queued) {
             if (in_array($provides, $queued)) {
                 unset($this->queue[$queued_name]);
                 $this->register($queued_name);
             }
         }
     }
 }
Beispiel #2
0
 public function __construct(Ioc $ioc, Directory $cache)
 {
     $this->ioc = $ioc;
     $preprocessor = $ioc->make(NomTransformer::class);
     $compiler = $ioc->make(Compiler::class);
     $pipeline = $ioc->make(Pipeline::class, [$cache, $compiler, [$preprocessor]]);
     $filesystem = new LocalDriver(__DIR__ . '/../templates');
     $templates = $filesystem->getDirectory('/');
     $hasher = new Sha1WeakHasher();
     $this->tailor = $ioc->make(Tailor::class, [$templates, $cache, $pipeline, $hasher]);
 }