Dietcube\Dispatcher::boot PHP Method

boot() public method

public boot ( )
    public function boot()
    {
        $this->app->loadConfig();
        $container = $this->container = new Container();
        $this->container['event_dispatcher'] = $this->event_dispatcher = new EventDispatcher();
        $this->container['app'] = $this->app;
        $this->app->setContainer($container);
        $config = $this->container['app.config'] = $this->app->getConfig();
        $this->container['logger'] = $logger = $this->app->createLogger($config->get('logger.path'), $config->get('logger.level', Logger::WARNING));
        $logger->debug('Application booted. env={env}', ['env' => $this->app->getEnv()]);
        $logger->debug('Config file loaded. config_files={files}', ['files' => implode(',', $this->app->getConfigFiles())]);
        $this->bootGlobals();
        $this->app->initHttpRequest($this->container);
        $this->app->init($this->container);
        if (!isset($this->container['router'])) {
            $this->container['router'] = new Router($this->container);
            $this->container['router']->addRoute($this->app->getRoute());
        }
        if (!isset($this->container['app.renderer'])) {
            $this->container['app.renderer'] = function () {
                return $this->createRenderer();
            };
        }
        $this->app->config($this->container);
        $this->event_dispatcher->dispatch(DietcubeEvents::BOOT, new BootEvent($this->app));
    }

Usage Example

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $app = new Application(dirname(dirname(__DIR__) . '/app'), Dispatcher::getEnv());
     $dispatcher = new Dispatcher($app);
     $dispatcher->boot();
     $user_service = new UserService();
     $body_measure_service = new BodyMeasureService($app->getContainer(), $app->getTmpDir());
     $users = $user_service->getUsers();
     $response = $body_measure_service->getData($users);
     $post_service = new PostService($app->getContainer());
     $post_service->post($response);
 }