Beispiel #1
0
 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;
 }
Beispiel #2
0
 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;
 }