Ejemplo n.º 1
0
 public function load(string $buildClass = Application::class)
 {
     // usually either 'app' or 'api' but may be other things.
     /** @var string $loaderContext */
     $loaderContext = $this->config['app.loader.context'];
     // the basePath to the folder of dependency configurations
     $basePath = $this->config['app.loader.base_path'];
     // collect definitions from the folder
     $this->definitions = Config::createFromFolder($basePath);
     $group = $this->definitions[$loaderContext];
     if (!isset($this->loaded[$loaderContext])) {
         $this->loadGroup($group);
         $this->loaded[] = $loaderContext;
     }
     return $this->container[$buildClass];
 }
Ejemplo n.º 2
0
 /**
  * @param array                    $paths
  * @param ContainerInterface|Forge $container
  *
  * @return array
  */
 private function registerClasses(array $paths, $container)
 {
     // we'll start by loading the configuration into the Forge Container
     $container->add(ContainerInterface::class, function () {
         return Forge::getInstance();
     });
     $container->add([Scope::class, 'context'], function () {
         return new Scope();
     });
     $container->add('environment', function () use($container) {
         return $container['GlobalScope'];
     });
     $container->singleton([GlobalScope::class, 'GlobalScope'], $global_scope = new GlobalScope($this));
     $container->singleton([Paths::class, 'Paths'], new Paths($paths));
     $container->singleton([Config::class, 'Config'], $config = Config::createFromFolder(\CONFIG));
     $container->singleton([Events::class, 'Events'], $events = Events::getInstance());
     $container->add('paths', function () use($container) {
         return $container['Paths'];
     });
     $container->add('config', function () use($container) {
         return $container['Config'];
     });
     return [$global_scope, $config, $events];
 }
Ejemplo n.º 3
0
 /**
  * @param array $paths
  *
  * @return Application
  */
 private function makeApplication(array $paths) : Application
 {
     // this is the Illuminate Container
     $container = Forge::getInstance();
     // we'll start by loading the configuration into the Forge Container
     $container->add([Scope::class, 'context'], function () {
         return new Scope();
     });
     $container->add('environment', function () use($container) {
         return $container['GlobalScope'];
     });
     $container->singleton([GlobalScope::class, 'GlobalScope'], $global_scope = new GlobalScope($this));
     $container->singleton([Paths::class, 'Paths'], new Paths($paths));
     $container->singleton([Config::class, 'Config'], $config = Config::createFromFolder(\CONFIG));
     $container->singleton([Events::class, 'Events'], $events = Events::getInstance());
     $container->add('paths', function () use($container) {
         return $container['Paths'];
     });
     $container->add('config', function () use($container) {
         return $container['Config'];
     });
     // the reason we are here
     $app = new NineApplication($container, $config, $events, $global_scope);
     // align the Nine Events object with the Core EventDispatcher (Symfony)
     Events::setEventDispatcher($app['dispatcher']);
     $app['app.context'] = 'app';
     // register the new Application
     $container->singleton([NineApplication::class, 'Application'], $app);
     // synchronize the Application instance with the forge.
     Forge::setApplication($app);
     // additional $app registrations. @formatter:off
     $app['container'] = $container;
     $app['global.scope'] = $global_scope;
     $app['app.factory'] = $this;
     $app['flashbag'] = $app->factory(function () use($app) {
         return $app['session']->getFlashBag();
     });
     $app['paths'] = $container['Paths'];
     //@formatter:on
     return $app;
 }