Example #1
0
 protected function createContainer() : array
 {
     $builder = new ContainerBuilder();
     $builder->bindInstance(clone $this);
     $builder->bindInstance(new Environment($this->env));
     $builder->share(LoggerInterface::class)->instance(LoopConfig::getLogger());
     $locator = new ResourceLocator($this->providers, $this->resourcePaths, $this->publicResourcePaths);
     $builder->bindInstance($locator);
     $builder->bindInstance(new Assets($this->env['K1_RESOURCE_PATH'], $locator));
     foreach ($this->providers as $provider) {
         $builder->bindInstance($provider);
     }
     $configs = new \SplPriorityQueue();
     $bindings = new \SplPriorityQueue();
     $paths = [\dirname(__DIR__) . '/config'];
     $this->collectPhpFiles($paths, $configs, 300);
     $this->collectPhpFiles($paths, $configs, 250, $this->contextName);
     $paths = [\dirname(__DIR__) . '/bind'];
     $this->collectPhpFiles($paths, $bindings, 300);
     $this->collectPhpFiles($paths, $bindings, 250, $this->contextName);
     foreach ($this->providers as $provider) {
         $this->collectPhpFiles($provider->getConfigPaths(), $configs, 200);
         $this->collectPhpFiles($provider->getConfigPaths(), $configs, 150, $this->contextName);
         $this->collectPhpFiles($provider->getBindingPaths(), $bindings, 200);
         $this->collectPhpFiles($provider->getBindingPaths(), $bindings, 150, $this->contextName);
     }
     $this->collectPhpFiles($this->configPaths, $configs, 100);
     $this->collectPhpFiles($this->configPaths, $configs, 50, $this->contextName);
     $this->collectPhpFiles($this->bindingPaths, $bindings, 100);
     $this->collectPhpFiles($this->bindingPaths, $bindings, 50, $this->contextName);
     $settings = new Settings();
     while (!$configs->isEmpty()) {
         $settings = $settings->mergeWith($this->loadSettings($configs->extract()));
     }
     while (!$bindings->isEmpty()) {
         $this->bind($bindings->extract(), $builder);
     }
     return [$builder, $settings];
 }