示例#1
0
 /**
  * Returns the *Singleton* instance of this class.
  *
  * @return Singleton The *Singleton* instance.
  */
 public static function getInstance()
 {
     if (null === self::$instance) {
         self::$instance = new static();
     }
     return self::$instance;
 }
示例#2
0
 /**
  * @return App
  */
 public static function instance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
示例#3
0
 public static function go($config)
 {
     self::$core = new \ArrayObject();
     self::$core->db = $config['db']['class']::getInstance()->connect($config['db']);
     self::$core->request = RequestFactory::create($config['data-type']);
     self::$core->response = ResponseFactory::create($config['data-type']);
     if ($config['cache']['on']) {
         self::$core->cache = $config['cache']['class']::getInstance()->create($config['cache']);
     }
     $controller = new Controller();
     $controller->doAction('index');
 }
示例#4
0
 /**
  * Метод запуска приложения
  * @throws Exception
  */
 public static function run()
 {
     try {
         // Загрузка и объединение конфигов
         if (!file_exists(PSR4_ROOT . '/config.local.php')) {
             throw new Exception('You have to create file config.local.php with your settings');
         }
         self::$config = (array) (require PSR4_ROOT . '/config.local.php') + (array) (require PSR4_ROOT . '/config.php');
         // Маршрутизация запроса
         $router = Router::getInstance();
         $route = $router->route($_SERVER['REQUEST_URI']);
         // Вызов обработчика
         self::_runAction($route['controller'], $route['action'], $route['params']);
     } catch (HttpException $e) {
         if ($e->getCode() === 404) {
             self::_runAction('error', '404', []);
         } else {
             self::_runAction('error', '500', ['message' => $e->getMessage()]);
         }
     } catch (\Exception $e) {
         self::_runAction('error', '500', ['message' => $e->getMessage()]);
     }
 }
示例#5
0
 public static function setRouter($router)
 {
     self::$router = $router;
 }