Пример #1
0
 /**
  *
  * @return Config
  */
 private function getConfig()
 {
     if (!$this->config instanceof Config) {
         $this->config = $this->diFactory->get('config');
     }
     return $this->config;
 }
Пример #2
0
 /**
  * Auto register namespace and class map
  * @throws Exception\RuntimeException
  * @todo Should cache register classmap
  */
 public function register()
 {
     $moduleHandler = $this->diFactory->get('moduleHandler');
     $autoloadConf = $moduleHandler->getModulesAutoloadConfig();
     if (isset($autoloadConf['namespaces'])) {
         if (!ArrayUtils::isHashTable($autoloadConf['namespaces'])) {
             throw new Exception\RuntimeException('Config autoload for namespace is invalid');
         }
         $this->loader->registerNamespaces($autoloadConf['namespaces']);
     }
     if (isset($autoloadConf['classmap'])) {
         $this->registerClassMap($autoloadConf['classmap']);
     }
     $this->loader->register();
     return $this;
 }
Пример #3
0
 public function run()
 {
     $config = $this->di->get('config');
     if (!isset($config['console'])) {
         throw new Exception\RuntimeException('Cannot find config for console');
     }
     $configConsole = $config['console']->toArray();
     foreach ($configConsole as $class) {
         $command = new $class();
         if (!$command instanceof Command) {
             $errMsg = sprintf('"%s" must be extends from "%s"', get_class($command), Command::class);
             throw new Exception\RuntimeException($errMsg);
         }
         $command->setDI($this->di);
         $this->app->add($command);
     }
     $this->app->run();
 }
Пример #4
0
 /**
  * Create error handler service
  * @param Di $di
  * @return \Phalex\Mvc\Exception\HandlerDefault
  * @throws InvalidArgumentException
  */
 public function createService(Di $di)
 {
     $required = ['views_dir' => null, 'template_500' => null, 'template_404' => null];
     $config = $di->get('config')['error_handler']->toArray();
     $errMsg = sprintf('Cannot create error handler "%s"', __CLASS__);
     if (!isset($config['options'])) {
         throw new InvalidArgumentException($errMsg);
     }
     $options = array_merge($required, $config['options']);
     if (empty($options['views_dir']) || empty($options['template_500']) || empty($options['template_404']) || ($realPath = realpath($options['views_dir'])) === false) {
         throw new InvalidArgumentException($errMsg);
     }
     $this->options = $options;
     $this->di = $di;
     $this->viewsDir = $realPath;
     return $this;
 }
Пример #5
0
 /**
  * Listen dispatch's events
  * @param \Phalex\Events\Listener\Dispatch $listener
  * @return \Phalex\Events\Listener
  */
 public function listenDispatchEvents(Listener\Dispatch $listener)
 {
     $this->di->get('eventsManager')->attach('dispatch', $listener, PHP_INT_MAX);
     return $this;
 }