コード例 #1
0
ファイル: CLIProvider.php プロジェクト: xinix-technology/bono
 /**
  * [initialize description]
  *
  * @return [type] [description]
  */
 public function initialize()
 {
     if ($this->app->config('bono.cli')) {
         $app = $this->app;
         $this->app->container->singleton('environment', function () {
             return \Bono\CLI\Environment::getInstance();
         });
         $this->app->notFound(function () use($app) {
             $argv = $GLOBALS['argv'];
             $app->log->error('Command not found');
             exit(255);
         });
         $this->app->error(function ($err) use($app) {
             $app->log->error('');
             $app->log->error('Error :' . $err->getMessage());
             $app->log->error('File  :' . $err->getFile() . ':' . $err->getLine());
             $app->log->error('');
             $app->log->error($err->getTraceAsString());
             $app->log->error('');
             $app->log->error('Done with errors');
             exit(1);
         });
         $commands = $this->app->config('bonocli.commands');
         if ($commands) {
             foreach ($commands as $commandClass) {
                 $command = new $commandClass();
                 $command->initialize($this->app);
             }
         }
     }
 }
コード例 #2
0
ファイル: App.php プロジェクト: xinix-technology/bono
 /**
  * Constructor
  *
  * @param array $userSettings Override settings from parameter
  */
 public function __construct(array $userSettings = array())
 {
     // FIXME ob started by php automatically but not skip on error
     // thats why i put line below
     ob_start();
     // this scope should not trigger any error {
     register_shutdown_function(array($this, 'shutdownHandler'));
     set_error_handler(array($this, 'errorHandler'));
     if (isset($_SERVER['HTTP_CONTENT_TYPE']) && empty($_SERVER['CONTENT_TYPE'])) {
         $_SERVER['CONTENT_TYPE'] = $_SERVER['HTTP_CONTENT_TYPE'];
     }
     if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
         if ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'http') {
             unset($_SERVER['HTTPS']);
         } else {
             $_SERVER['HTTPS'] = 'on';
         }
         if (isset($_SERVER['HTTP_X_FORWARDED_PORT'])) {
             $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT'];
         }
     }
     if (PHP_SAPI === 'cli') {
         \Bono\CLI\Environment::getInstance();
     }
     // }
     try {
         // DO NOT add something above except you sure that it wont break
         parent::__construct($userSettings);
         $this->container->singleton('request', function ($c) {
             return new \Bono\Http\Request($c['environment']);
         });
         $this->container->singleton('response', function ($c) {
             return new \Bono\Http\Response();
         });
         $this->container->singleton('theme', function ($c) {
             $config = $c['settings']['bono.theme'];
             if (is_array($config)) {
                 $themeClass = $config['class'];
             } else {
                 $themeClass = $config;
                 $config = array();
             }
             return $themeClass instanceof \Bono\Theme\Theme ? $themeClass : new $themeClass($config);
         });
         $app = $this;
         $oldView = $this->view;
         $this->view = function ($c) use($app, $oldView) {
             if ($app->theme && ($view = $app->theme->getView())) {
                 return $view;
             } else {
                 return $oldView;
             }
         };
         $this->configure();
         $this->configureHandler();
         $this->configureAliases();
         $this->configureProvider();
         $this->configureMiddleware();
         $this->configureFilters();
         if ($this->config('autorun')) {
             $this->run();
         }
     } catch (\Slim\Exception\Stop $e) {
         // noop
     } catch (\Exception $e) {
         $this->configureHandler()->error($e);
     }
 }