Example #1
0
 /**
  * Echo image data to output buffer
  * @param string $a_mime Set image mime
  */
 function output($a_mime = 'image/png')
 {
     $mime = trim(strtolower($a_mime));
     if ($this->m_handle) {
         ob_start();
         switch ($mime) {
             default:
             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;
         }
         Zoombi_Response::getInstance()->setContent(ob_get_contents());
         ob_end_clean();
     }
     Zoombi_Response::getInstance()->setContentType($mime);
     return $this;
 }
Example #2
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 Zoombi_Request::getInstance();
         case 'response':
             return Zoombi_Response::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 'loader':
         case 'load':
             return $this->getModule()->getLoader();
         case 'acl':
             return $this->getModule()->getAcl();
     }
     try {
         return $this->getProperty($a_property);
     } catch (Zoombi_Exception $e) {
         if ($e->getCode() == Zoombi_Exception::EXC_NO_PROPERTY) {
             return Zoombi::$null;
         }
     }
     return Zoombi::$null;
 }
 /**
  * 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'));
     register_shutdown_function(array(&$this, '_shutdown'));
     // 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 Zoombi_Event($this, 'preExecute'));
         // Notify befor route start
         if (!$this->getFlag(self::FLAG_NO_ROUTE)) {
             // Attach routing rules
             $routes = new Zoombi_Config();
             $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 Zoombi_Url($this->getConfig()->getValue('baseurl'));
             if (strstr($request, $url->path) == 0) {
                 $request = substr($request, strlen($url->path));
             }
             $router->setRequest($request);
             $this->emit(new Zoombi_Event($this, 'preRoute', $router->getRequest()));
             $r_path = (string) $router->getRequest();
             if (empty($r_path)) {
                 $r_path = '_root_';
             }
             //Do route rewriting
             $redirect = $router->rewrite($r_path);
             $router->setRedirect($redirect);
             $this->emit(new Zoombi_Event($this, 'postRoute', $router->getRedirect()));
             $path = clone $router->getRedirect();
             $s = $path->getSegment(0);
             if ($s == $this->getName() or $s == Zoombi_Module::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 Zoombi_Exception_Controller::EXC_QUIT:
                 $this->getConfig()->setValue('output', false);
                 $this->emit(new Zoombi_Event($this, 'onQuit'));
                 break;
             case Zoombi_Exception_Controller::EXC_QUIT_OUTPUT:
                 $this->getConfig()->setValue('output', true);
                 $this->emit(new Zoombi_Event($this, 'onQuit'));
                 break;
             case Zoombi_Exception_Controller::EXC_AUTH:
                 $this->emit(new Zoombi_Event($this, 'onError', 401, $e));
                 $this->emit(new Zoombi_Event($this, 'on401', $this->getRoute()));
                 $this->route('_401_');
                 break;
             case Zoombi_Exception_Controller::EXC_DENY:
                 $this->emit(new Zoombi_Event($this, 'onError', 403, $e));
                 $this->emit(new Zoombi_Event($this, 'on403', $this->getRoute()));
                 $this->route('_403_');
                 break;
             case Zoombi_Exception_Controller::EXC_LOAD:
             case Zoombi_Exception_Controller::EXC_NO_FILE:
             case Zoombi_Exception_Controller::EXC_ACTION:
                 $this->triggerError($e);
                 $this->emit(new Zoombi_Event($this, 'onError', 404, $e));
                 $this->emit(new Zoombi_Event($this, 'on404', $this->getRoute()));
                 $this->route('_404_');
                 break;
             default:
                 $this->triggerError($e);
                 $this->emit(new Zoombi_Event($this, 'onError', 500, $e));
                 $this->emit(new Zoombi_Event($this, 'on500', $e));
                 $this->route('_500_');
                 break;
         }
     }
     restore_error_handler();
     restore_exception_handler();
     if (Zoombi::ack($this->getConfig()->getValue('output', false))) {
         ob_start();
         if ($this->outputLength() > 0) {
             $this->outputFlush();
         }
         Zoombi_Response::getInstance()->appendContent(ob_get_contents());
         ob_end_clean();
         $this->emit(new Zoombi_Event($this, 'onOutput'));
         Zoombi_Response::getInstance()->output();
     }
     $this->emit(new Zoombi_Event($this, 'postExecute'));
     error_reporting($olderr);
 }
Example #4
0
 /**
  * Echo document data
  * @return Zoombi_Document
  */
 public function &output($a_encoding = null)
 {
     if ($a_encoding) {
         $this->setCharset($a_encoding);
     }
     Zoombi_Response::getInstance()->setContentType($this->getMime())->setContentCharset($this->getCharset());
     echo $this->compile();
     return $this;
 }
Example #5
0
 protected function after()
 {
     $this->setOutput($this->document->compile());
     Zoombi_Response::getInstance()->setContentType($this->document->getMime())->setContentCharset($this->document->getCharset());
 }