public function __construct() { $app = self::app(); if (!is_null($app)) { throw new Yaf_Exception('Only one application can be initialized'); } Yaf_G::init(); //这里主要是配置文件的加载 // request initialization if (isset($_SERVER['REQUEST_METHOD'])) { //判断http请求还是cli请求 $request = new Yaf_Request_Http(); //获取请求的url路径和基础路径,以及请求方式 } else { $request = new Yaf_Request_Cli(); } if ($request == null) { throw new Yaf_Exception('Initialization of request failed'); } // dispatcher $this->_dispatcher = Yaf_Dispatcher::getInstance(); //将调度对象赋值给app对象的属性,并在调度对象的属性中添加路由对象,单例 if ($this->_dispatcher == null || !$this->_dispatcher instanceof Yaf_Dispatcher) { throw new Yaf_Exception('Instantiation of dispatcher failed'); } $this->_dispatcher->setRequest($request); //把请求对象赋值给调度对象的属性中 self::$_app = $this; }
public function __construct($config, $env = null) { $app = self::app(); if (!is_null($app)) { throw new Yaf_Exception_StartupError('Only one application can be initialized'); } $this->_environ = $env; $config = $this->_loadConfig($config); if ($config == null || !$config instanceof Yaf_Config_Abstract || $this->parseOptions($config->toArray()) != true) { throw new Yaf_Exception_StartupError('Initialization of application config failed'); } //$this->parseOptions($config->toArray()); $this->_config = $config; //request initialization $request = new Yaf_Request_Http(); if ($request == null) { throw new Yaf_Exception_StartupError('Initialization of request failed'); } //dispatcher $this->_dispatcher = Yaf_Dispatcher::getInstance(); if ($this->_dispatcher == null || !$this->_dispatcher instanceof Yaf_Dispatcher) { throw new Yaf_Exception_StartupError('Instantiation of dispatcher failed'); } $this->_dispatcher->setRequest($request); //loader initialization $loader = Yaf_Loader::getInstance(isset($this->_options['local_library']) ? $this->_options['local_library'] : '', Yaf_G::iniGet('yaf.library')); if ($loader == null || !$loader instanceof Yaf_Loader) { throw new Yaf_Exception_StartupError('Initialization of application auto loader failed'); } if (isset($this->_options['local_namespace']) && $this->_options['local_namespace'] != '') { $namespace = str_replace(array(',', ' '), array(':', ':'), $this->_options['local_namespace']); $loader->registerLocalNamespace($namespace); } self::$_app = $this; if (Yaf_G::get('throwException') == false) { set_exception_handler(array($this, 'exceptionHandler')); } }
public function __construct() { $app = self::app(); if (!is_null($app)) { throw new Yaf_Exception('Only one application can be initialized'); } Yaf_G::init(); // request initialization if (isset($_SERVER['REQUEST_METHOD'])) { $request = new Yaf_Request_Http(); } else { $request = new Yaf_Request_Cli(); } if ($request == null) { throw new Yaf_Exception('Initialization of request failed'); } // dispatcher $this->_dispatcher = Yaf_Dispatcher::getInstance(); if ($this->_dispatcher == null || !$this->_dispatcher instanceof Yaf_Dispatcher) { throw new Yaf_Exception('Instantiation of dispatcher failed'); } $this->_dispatcher->setRequest($request); self::$_app = $this; }