Exemplo n.º 1
0
 public function __construct($config, $type)
 {
     if (is_string($config)) {
         $config = (require $config);
     }
     if (isset($config['app_path'])) {
         $this->setBasePath($config['app_path']);
         Base::setAppPath($config['app_path']);
         Loader::setPathOfAlias('app', Base::getAppPath());
         Loader::setPathOfAlias('public', dirname($_SERVER['SCRIPT_FILENAME']));
         unset($config['app_path']);
     } else {
         throw new Exception('Application: missing application\'s config "app_path"');
     }
     if (!isset($config['namespace'])) {
         throw new Exception('Application: missng config "namespace"');
     }
     Loader::addNamespace($config['namespace'], dirname(Base::getAppPath()));
     $this->setAppNamespace($config['namespace']);
     if (isset($config['import'])) {
         $this->_import($config['import']);
         unset($config['import']);
     }
     $this->_type = $type;
     $this->preInit();
     $this->configuration($config);
     $this->_init();
     $this->afterInit();
     /**
      * @TODO removed since version 1.0.2, application custom error handler
      */
     //        set_error_handler(array($this,'handleError'),error_reporting());
 }
Exemplo n.º 2
0
 public function parseUrl($url)
 {
     $url = trim($url, '/');
     if (null == $url) {
         throw new ApiException('Invalid request !', 404);
     }
     $segment = explode('/', $url);
     $_cf = explode('.', end($segment));
     //check define format
     if (isset($_cf[1])) {
         $this->_format = $_cf[1];
         $segment[count($segment) - 1] = $_cf[0];
     }
     $size = sizeof($segment);
     $router = array();
     for ($i = 0; $i < $size; ++$i) {
         $router[$i] = Inflection::camelize($segment[$i]);
     }
     for ($i = $size - 1; $i >= 0; --$i) {
         $router = array_slice($router, 0, $i + 1);
         $_camelName = implode("\\", $router);
         $_path = implode(DIRECTORY_SEPARATOR, $router);
         if (false !== file_exists($file = Base::getAppPath() . '/Controller/' . $_path . '.php')) {
             $this->_api = trim($_camelName, "\\");
             break;
         }
     }
     if (null == $this->_api) {
         throw new ApiException('API not found', 404);
     }
     $segment = array_slice($segment, $i + 1);
     if (!empty($segment)) {
         $this->_method = array_shift($segment);
         $this->_params = !empty($segment) ? $segment : array();
     }
 }
Exemplo n.º 3
0
 private function _parseControllers($route)
 {
     if (false === is_array($route)) {
         $route = explode('/', $route);
     }
     $_path = '';
     $_camelName = '';
     $size = sizeof($route);
     for ($i = 0; $i < $size; ++$i) {
         $route[$i] = Inflection::camelize($route[$i]);
     }
     for ($i = $size - 1; $i >= 0; --$i) {
         $_camelName = implode("\\", array_slice($route, 0, $i + 1));
         $_path = implode(DIRECTORY_SEPARATOR, array_slice($route, 0, $i + 1));
         if (false !== file_exists($file = Base::getAppPath() . '/Controller/' . $_path . '.php')) {
             $this->_camelControllerName = trim($_camelName, "\\");
             break;
         }
     }
     return $i;
 }
Exemplo n.º 4
0
 /**
  * Get Session
  * @deprecated Change method to \Flywheel\Session\Session::getInstance()
  *
  * @throws Exception
  * @return \Flywheel\Session\Session
  */
 public static function getSession()
 {
     if (!Base::getApp()) {
         throw new Exception('Factory: Session must start after the application is initialized!');
     }
     if (!isset(self::$_registry['session'])) {
         $config = ConfigHandler::load('app.config.session', 'session', false) or $config = ConfigHandler::load('global.config.session', 'session');
         if (false == $config) {
             throw new Exception('Session: config file not found, "session.cfg.php" must be exist at globals/config or ' . Base::getAppPath() . ' config directory');
         }
         $class = self::$_classesList['Session'];
         self::$_registry['session'] = new $class($config);
     }
     return self::$_registry['session'];
 }