コード例 #1
0
 public function &__get($a_property)
 {
     switch ($a_property) {
         default:
             break;
         case 'application':
             return Zoombi::getApplication();
         case 'database':
             return Zoombi::getApplication()->getDatabase();
         case 'router':
             return $this->getModule()->getRouter();
         case 'session':
             return Zoombi::getApplication()->getSession();
         case 'request':
             return ZRequest::getInstance();
         case 'response':
             return ZResponse::getInstance();
         case 'module':
             return $this->getModule();
         case 'route':
             return $this->getModule()->getRoute();
         case 'registry':
             return $this->getModule()->getRegistry();
         case 'config':
             return $this->getModule()->getConfig();
         case 'language':
             return $this->getModule()->getLanguage();
         case 'load':
             return $this->getModule()->getLoader();
         case 'acl':
             return $this->getModule()->getAcl();
     }
     try {
         return $this->getProperty($a_property);
     } catch (ZException $e) {
         if ($e->getCode() == ZException::EXC_NO_PROPERTY) {
             return Zoombi::$null;
         }
     }
     return Zoombi::$null;
 }
コード例 #2
0
ファイル: image.php プロジェクト: BGCX261/zoombi-svn-to-git
 function output($a_mime = 'image/png')
 {
     $mime = trim(strtolower($a_mime));
     if ($this->m_handle) {
         ob_start();
         switch ($mime) {
             case 'jpg':
             case 'jpeg':
             case 'image/jpeg':
                 imagejpeg($this->m_handle);
                 break;
             case 'png':
             case 'image/png':
                 imagepng($this->m_handle);
                 break;
             case 'gif':
             case 'image/gif':
                 imagegif($this->m_handle);
                 break;
             case 'gd':
             case 'image/gd':
                 imagegd($this->m_handle);
                 break;
             case 'gd2':
             case 'image/gd2':
                 imagegd2($this->m_handle);
                 break;
             case 'bmp':
             case 'wbmp':
             case 'image/bmp':
             case 'image/wbmp':
                 imagewbmp($this->m_handle);
                 break;
         }
         ZResponse::getInstance()->setContent(ob_get_contents());
         ob_end_clean();
     }
     ZResponse::getInstance()->setContentType($mime);
 }
コード例 #3
0
 protected function after()
 {
     $this->setOutput($this->document->compile());
     ZResponse::getInstance()->setContentType($this->document->getMime())->setContentCharset($this->document->getCharset());
 }
コード例 #4
0
 /**
  * Execute application
  */
 public final function execute()
 {
     $_errtype = E_ALL;
     // Set application plugin manager listen global event dispatcher
     $this->getPluginManager()->setTarget(Zoombi::getDispatcher());
     $this->getDispatcher()->connect('_triggerError', array($this, '_error_trigger'));
     try {
         // Notify for start execution
         $this->emit(new ZEvent($this, 'preExecute'));
         // Attach error and exception handlers if applicatio execution mode is 'debug'
         if ($this->isMode(self::MODE_DEBUG)) {
             $old_errr = error_reporting($_errtype);
             set_error_handler(array($this, '_error_handler'), $_errtype);
             //set_exception_handler(array( $this, '_exception_handler' ));
         }
         // Notify befor route start
         //$this->emit(new ZEvent($this, 'preRoute'));
         if (!$this->getFlag(self::FLAG_NO_ROUTE)) {
             $request = null;
             $rvar = $_SERVER['REQUEST_URI'];
             // Attach routing rules to router
             $routes = new ZConfig();
             $router = $this->getRouter();
             $rs = $this->getConfig()->getValue('routes', null);
             switch (gettype($rs)) {
                 case 'array':
                 case 'object':
                     $routes->setData($rs);
                     break;
                 case 'string':
                     $cf = $rs;
                     if (!file_exists($cf)) {
                         $cf = $this->fromBaseDir($cf);
                     }
                     if (file_exists($cf)) {
                         $routes->fromFile($cf);
                     }
                     break;
             }
             $ra = $routes->toArray();
             $router->setRules($ra);
             unset($routes);
             $router->setRequest($rvar);
             $this->emit(new ZEvent($this, 'preRoute', $router->getRequest()));
             $redir = $router->rewrite($router->getRequest());
             $router->setRedirect($redir)->setCurrent($redir)->setForward($redir);
             $this->emit(new ZEvent($this, 'postRoute', $redir));
             $path = $router->getRedirect();
             if ($path->getSegment(0) == $this->getName()) {
                 $path->pop_start();
             }
             $curr = null;
             $fpath = $this->routePath($path, $curr, true);
             $router->setCurrent($curr)->setForward($curr);
             if ($fpath->isInvalid()) {
                 throw new ZException('Page not found', ZControllerException::EXC_ACTION);
             }
             if ($curr->getSegment(0) == $this->getName()) {
                 $curr->pop_start();
             }
             $this->route($curr);
         }
     } catch (ZException $e) {
         switch ($e->getCode()) {
             case ZControllerException::EXC_QUIT:
                 $this->getConfig()->setValue('output', false);
                 break;
             case ZControllerException::EXC_QUIT_OUTPUT:
                 $this->getConfig()->setValue('output', true);
                 break;
             case ZControllerException::EXC_LOAD:
             case ZControllerException::EXC_NO_FILE:
             case ZControllerException::EXC_ACTION:
                 $this->emit(new ZEvent($this, 'onError', 404, $e));
                 $this->emit(new ZEvent($this, 'on404', $this->getRoute()));
                 break;
             case ZControllerException::EXC_DENY:
                 $this->emit(new ZEvent($this, 'onError', 403, $e));
                 $this->emit(new ZEvent($this, 'on403', $this->getRoute()));
                 break;
             case ZControllerException::EXC_AUTH:
                 $this->emit(new ZEvent($this, 'onError', 401, $e));
                 $this->emit(new ZEvent($this, 'on401', $this->getRoute()));
                 break;
             default:
                 $this->emit(new ZEvent($this, 'onError', 500, $e));
                 $this->emit(new ZEvent($this, 'on500', $e));
                 break;
         }
     }
     $responce = ZResponse::getInstance();
     if (Zoombi::ack($this->getConfig()->getValue('output', false))) {
         ob_start();
         $this->emit(new ZEvent($this, 'onOutput'));
         if ($this->outputLength() > 0) {
             $this->outputFlush();
         }
         if (Zoombi::ack($this->getConfig()->get('showtrace', false))) {
             ZDebug::printTraces();
         }
         if (Zoombi::ack($this->getConfig()->get('showerror', false))) {
             $this->showErrors();
         }
         $cnt = ob_get_contents();
         ob_end_clean();
         $responce->appendContent($cnt);
     }
     $this->emit(new ZEvent($this, 'postExecute'));
     if ($this->isMode(self::MODE_DEBUG)) {
         restore_error_handler();
         error_reporting($old_errr);
     }
     $responce->output();
 }
コード例 #5
0
 /**
  * Execute application
  */
 private final function _execute()
 {
     $_errtype = E_ALL;
     // Set application plugin manager listen global event dispatcher
     $this->getPluginManager()->setTarget(Zoombi::getDispatcher());
     $this->getDispatcher()->connect('_triggerError', array(&$this, '_error_trigger'));
     try {
         // Notify for start execution
         $this->emit(new ZEvent($this, 'preExecute'));
         // Attach error and exception handlers if applicatio execution mode is 'debug'
         if ($this->isMode(self::MODE_DEBUG)) {
             $old_errr = error_reporting($_errtype);
             set_error_handler(array($this, '_error_handler'), $_errtype);
             //set_exception_handler(array( $this, '_exception_handler' ));
         }
         // Notify befor route start
         //$this->emit(new ZEvent($this, 'preRoute'));
         if (!$this->getFlag(self::FLAG_NO_ROUTE)) {
             $request = null;
             // Process request info
             $req_qry = explode('?', $_SERVER['REQUEST_URI'], 2);
             $request = array_shift($req_qry);
             // Get content rewrite variabe
             $rt = $this->getConfig()->getValue('routevar', 'rt');
             $rvar = null;
             if (isset($_GET[$rt])) {
                 $rvar = $_GET[$rt];
                 unset($_GET[$rt]);
             }
             if ($req_qry) {
                 $rvar .= '?' . $req_qry[0];
             }
             // Attach routing rules to router
             $routes = new ZConfig();
             $rs = $this->getConfig()->getValue('routes', null);
             switch (gettype($rs)) {
                 case 'array':
                 case 'object':
                     $routes->setData($rs);
                     break;
                 case 'string':
                     $routes->fromFile($this->fromBaseDir($rs));
                     break;
             }
             $this->getRouter()->setRules($routes->toArray());
             unset($routes);
             $this->emit(new ZEvent($this, 'preRoute', $rvar));
             $this->getRouter()->setRequest($rvar);
             $redir = $this->getRouter()->route($rvar);
             $p = new ZRoute($redir);
             if (!$this->getLoader()->hasModule($p->getModule()) and $p->getModule() != $this->getName()) {
                 $p->push_start($this->getName());
             }
             $fix = $this->fixroute($p);
             $this->getRouter()->setRedirect($fix)->setCurrent($fix)->setForward($fix);
             $this->emit(new ZEvent($this, 'postRoute', $fix));
             $approute = true;
             if ($p->getModule() == $this->getName()) {
                 $p->pop_start();
             }
             $this->route($p, array('approute'));
             $approute = false;
         }
     } catch (ZException $e) {
         switch ($e->getCode()) {
             case ZControllerException::EXC_QUIT:
                 $this->getConfig()->setValue('output', false);
                 break;
             case ZControllerException::EXC_QUIT_OUTPUT:
                 $this->getConfig()->setValue('output', true);
                 break;
             case ZControllerException::EXC_LOAD:
             case ZControllerException::EXC_NO_FILE:
             case ZControllerException::EXC_ACTION:
                 $this->emit(new ZEvent($this, 'onError', 404, $e));
                 $this->emit(new ZEvent($this, 'on404', $this->getRoute()));
                 break;
             case ZControllerException::EXC_DENY:
                 $this->emit(new ZEvent($this, 'onError', 403, $e));
                 $this->emit(new ZEvent($this, 'on403', $this->getRoute()));
                 break;
             case ZControllerException::EXC_AUTH:
                 $this->emit(new ZEvent($this, 'onError', 401, $e));
                 $this->emit(new ZEvent($this, 'on401', $this->getRoute()));
                 break;
             default:
                 $this->emit(new ZEvent($this, 'onError', 500, $e));
                 $this->emit(new ZEvent($this, 'on500', $e));
                 break;
         }
     }
     if (Zoombi::ack($this->getConfig()->getValue('output', false))) {
         ob_start();
         if (Zoombi::ack($this->getConfig()->get('showerror', 'false'))) {
             foreach ($this->m_errors as $e) {
                 $this->showError($e);
             }
         }
         $this->emit(new ZEvent($this, 'onOutput'));
         $cnt = ob_get_contents();
         ob_end_clean();
         ZResponse::getInstance()->setContent(ZResponse::getInstance()->getContent() . $cnt);
     }
     $this->emit(new ZEvent($this, 'postExecute'));
     if ($this->isMode(self::MODE_DEBUG)) {
         restore_error_handler();
         error_reporting($old_errr);
     }
     ZResponse::getInstance()->output();
 }
コード例 #6
0
 private function _request_auth()
 {
     ZResponse::getInstance()->setCode(401)->setMessage('Unauthorized')->setHeader('Date', date_to_string(date_create(DATE_RSS)))->setHeader('WWW-Authenticate', 'Basic realm="Secure area"');
     throw new ZControllerException('Unauthorized', ZControllerException::EXC_AUTH);
 }
コード例 #7
0
ファイル: image.php プロジェクト: BGCX261/zoombi-svn-to-git
 function output($a_mime = 'image/png')
 {
     ob_start();
     imagepng($this->m_handle);
     $c = ob_get_contents();
     ob_end_clean();
     ZResponse::getInstance()->setContentType($a_mime)->setHeader('Accept-Ranges', 'bytes')->setHeader('Content-Length', strlen($c))->setHeader('Content-MD5', md5($c));
     echo $c;
 }
コード例 #8
0
 /**
  * Send document headers
  * @param string $a_encoding
  * @return ZDocument
  */
 public function &outputHeader($a_encoding = 'utf-8')
 {
     ZResponse::getInstance()->setContentType($this->getMime(), $a_encoding)->output();
     return $this;
 }
コード例 #9
0
 /**
  * Echo document data
  * @return ZDocument
  */
 public function &output($a_encoding = null)
 {
     if ($a_encoding) {
         $this->setCharset($a_encoding);
     }
     ZResponse::getInstance()->setContentType($this->getMime())->setContentCharset($this->getCharset());
     echo $this->compile();
     return $this;
 }
コード例 #10
0
 /**
  * Execute application
  */
 public final function execute($a_route_url = null)
 {
     // Attach error and exception handlers
     $olderr = error_reporting(E_ALL);
     set_error_handler(array($this, '_error_handler'));
     set_exception_handler(array($this, '_exception_handler'));
     // Set application plugin manager listen global event dispatcher
     $this->getPluginManager()->setTarget(Zoombi::getDispatcher());
     $this->getDispatcher()->connect('_triggerError', array($this, '_error_trigger'));
     try {
         // Notify for start execution
         $this->emit(new ZEvent($this, 'preExecute'));
         // Notify befor route start
         if (!$this->getFlag(self::FLAG_NO_ROUTE)) {
             // Attach routing rules to router
             $routes = new ZConfig();
             $router = $this->getRouter();
             $rs = $this->getConfig()->getValue('routes', null);
             switch (gettype($rs)) {
                 case 'array':
                 case 'object':
                     $routes->setData($rs);
                     break;
                 case 'string':
                     $cf = $rs;
                     if (!file_exists($cf)) {
                         $cf = $this->fromBaseDir($cf);
                     }
                     if (file_exists($cf)) {
                         $routes->fromFile($cf);
                     }
                     break;
             }
             $ra = $routes->toArray();
             $router->setRules($ra);
             unset($routes);
             $request = $a_route_url ? $a_route_url : $_SERVER['REQUEST_URI'];
             $url = new ZUrl($this->getConfig()->getValue('baseurl'));
             if (strstr($request, $url->path) == 0) {
                 $request = substr($request, strlen($url->path));
             }
             $router->setRequest($request);
             $this->emit(new ZEvent($this, 'preRoute', $router->getRequest()));
             $redirect = $router->rewrite((string) $router->getRequest());
             $router->setRedirect($redirect);
             $this->emit(new ZEvent($this, 'postRoute', $router->getRedirect()));
             $path = clone $router->getRedirect();
             $s = $path->getSegment(0);
             if ($s == $this->getName() or $s == ZModule::DEFAULT_MODULE_NAME) {
                 if (!$this->getLoader()->hasController($s)) {
                     $path->pop_start();
                 }
             }
             $this->exec_route = $this->_route((string) $path);
             if ($this->exec_route) {
                 $this->getRouter()->setCurrent($this->exec_route);
                 $this->route($this->exec_route);
             }
         }
     } catch (Exception $e) {
         switch ($e->getCode()) {
             case ZControllerException::EXC_QUIT:
                 $this->getConfig()->setValue('output', false);
                 $this->emit(new ZEvent($this, 'onQuit'));
                 break;
             case ZControllerException::EXC_QUIT_OUTPUT:
                 $this->getConfig()->setValue('output', true);
                 $this->emit(new ZEvent($this, 'onQuit'));
                 break;
             case ZControllerException::EXC_AUTH:
                 $this->emit(new ZEvent($this, 'onError', 401, $e));
                 $this->emit(new ZEvent($this, 'on401', $this->getRoute()));
                 break;
             case ZControllerException::EXC_DENY:
                 $this->emit(new ZEvent($this, 'onError', 403, $e));
                 $this->emit(new ZEvent($this, 'on403', $this->getRoute()));
                 break;
             case ZControllerException::EXC_LOAD:
             case ZControllerException::EXC_NO_FILE:
             case ZControllerException::EXC_ACTION:
                 $this->emit(new ZEvent($this, 'onError', 404, $e));
                 $this->emit(new ZEvent($this, 'on404', $this->getRoute()));
                 break;
             default:
                 $this->emit(new ZEvent($this, 'onError', 500, $e));
                 $this->emit(new ZEvent($this, 'on500', $e));
                 break;
         }
     }
     restore_error_handler();
     restore_exception_handler();
     if (Zoombi::ack($this->getConfig()->getValue('output', false))) {
         ob_start();
         if ($this->outputLength() > 0) {
             $this->outputFlush();
         }
         if (Zoombi::ack($this->getConfig()->get('showtrace', false))) {
             ZDebug::printTraces();
         }
         if (Zoombi::ack($this->getConfig()->get('showerror', false))) {
             $this->showErrors();
         }
         ZResponse::getInstance()->appendContent(ob_get_contents());
         ob_end_clean();
         $this->emit(new ZEvent($this, 'onOutput'));
         ZResponse::getInstance()->output();
     }
     $this->emit(new ZEvent($this, 'postExecute'));
     error_reporting($olderr);
 }
コード例 #11
0
 private function _request_auth()
 {
     ZResponse::getInstance()->setCode(401)->setMessage('Unauthorized')->setHeader('Date', date_create(DATE_RSS))->setHeader('WWW-Authenticate', 'Basic realm="Secure area"');
     //Zoombi::getApplication()->getRouter()->setCurrent('error/401');
     throw new ZControllerException('Unauthorized', ZControllerException::EXC_AUTH);
 }