예제 #1
0
 /**
  * Retrieve front controller instance
  *
  * @return EvHttp_Controller_Front
  */
 public function getFrontController()
 {
     if (null === $this->_frontController) {
         $this->_frontController = EvHttp_Controller_Front::getInstance();
     }
     return $this->_frontController;
 }
예제 #2
0
파일: main.php 프로젝트: dreamsxin/Kellner
 public function __construct($addr = "127.0.0.1", $port = 8080)
 {
     $this->port = $port;
     $this->addr = $addr;
     $this->_startupSuperGlobal();
     // Setup basic stuff
     error_reporting(E_ALL & ~E_NOTICE);
     $base = realpath(dirname(__FILE__) . '/../');
     $paths = array('.', realpath($base . '/library'), get_include_path());
     $this->base = $base;
     // Setup autoloading ...
     set_include_path(implode(PATH_SEPARATOR, $paths));
     require_once 'Zend/Loader/Autoloader.php';
     $autoloader = Zend_Loader_Autoloader::getInstance();
     $autoloader->registerNamespace('EvHttp_');
     $resourceLoader = new Zend_Loader_Autoloader_Resource(array('basePath' => realpath($base . '/application'), 'namespace' => '', 'resourceTypes' => array('model' => array('namespace' => 'Model', 'path' => 'models/'), 'form' => array('namespace' => 'Form', 'path' => 'forms/'))));
     // Load config
     $this->config = new Zend_Config_Ini($this->base . '/deploy/config.ini', 'default');
     Zend_Registry::set('config', $this->config);
     // Connect database
     $dbType = $this->config->database->type;
     $params = $this->config->database->toArray();
     $db = Zend_Db::factory($dbType, $params);
     Zend_Db_Table::setDefaultAdapter($db);
     Zend_Registry::set('db', $db);
     // Setup extended front controller.
     $this->controller = EvHttp_Controller_Front::getInstance();
     $this->controller->throwExceptions(true);
     $this->controller->returnResponse(true);
     $this->controller->setDefaultAction('index');
     $this->controller->setControllerDirectory(array('default' => $base . '/application/controllers'));
 }
예제 #3
0
 /**
  * Instantiates route based on passed Zend_Config structure
  */
 public static function getInstance(Zend_Config $config)
 {
     $frontController = EvHttp_Controller_Front::getInstance();
     $defs = $config->defaults instanceof Zend_Config ? $config->defaults->toArray() : array();
     $dispatcher = $frontController->getDispatcher();
     $request = $frontController->getRequest();
     return new self($defs, $dispatcher, $request);
 }
예제 #4
0
 /**
  * Constructor
  *
  * Register action stack plugin
  * 
  * @return void
  */
 public function __construct()
 {
     $front = EvHttp_Controller_Front::getInstance();
     if (!$front->hasPlugin('EvHttp_Controller_Plugin_ActionStack')) {
         /**
          * @see EvHttp_Controller_Plugin_ActionStack
          */
         require_once 'EvHttp/Controller/Plugin/ActionStack.php';
         $this->_actionStack = new EvHttp_Controller_Plugin_ActionStack();
         $front->registerPlugin($this->_actionStack, 97);
     } else {
         $this->_actionStack = $front->getPlugin('EvHttp_Controller_Plugin_ActionStack');
     }
 }
예제 #5
0
 /**
  * Inflect based on provided vars
  *
  * Allowed variables are:
  * - :moduleDir - current module directory
  * - :module - current module name
  * - :controller - current controller name
  * - :action - current action name
  * - :suffix - view script file suffix
  *
  * @param  array $vars
  * @return string
  */
 protected function _translateSpec(array $vars = array())
 {
     $inflector = $this->getInflector();
     $request = $this->getRequest();
     $dispatcher = $this->_frontController->getDispatcher();
     $module = $dispatcher->formatModuleName($request->getModuleName());
     $controller = $request->getControllerName();
     $action = $dispatcher->formatActionName($request->getActionName());
     $params = compact('module', 'controller', 'action');
     foreach ($vars as $key => $value) {
         switch ($key) {
             case 'module':
             case 'controller':
             case 'action':
             case 'moduleDir':
             case 'suffix':
                 $params[$key] = (string) $value;
                 break;
             default:
                 break;
         }
     }
     if (isset($params['suffix'])) {
         $origSuffix = $this->getViewSuffix();
         $this->setViewSuffix($params['suffix']);
     }
     if (isset($params['moduleDir'])) {
         $origModuleDir = $this->_getModuleDir();
         $this->_setModuleDir($params['moduleDir']);
     }
     $filtered = $inflector->filter($params);
     if (isset($params['suffix'])) {
         $this->setViewSuffix($origSuffix);
     }
     if (isset($params['moduleDir'])) {
         $this->_setModuleDir($origModuleDir);
     }
     return $filtered;
 }
예제 #6
0
 /**
  * Prepare data for autocompletion
  * 
  * @param  mixed   $data 
  * @param  boolean $keepLayouts 
  * @return string
  */
 public function prepareAutoCompletion($data, $keepLayouts = false)
 {
     if (!$data instanceof Zend_Dojo_Data) {
         require_once 'Zend/Dojo/Data.php';
         $items = array();
         foreach ($data as $key => $value) {
             $items[] = array('label' => $value, 'name' => $value);
         }
         $data = new Zend_Dojo_Data('name', $items);
     }
     if (!$keepLayouts) {
         require_once 'EvHttp/Controller/Action/HelperBroker.php';
         EvHttp_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
         require_once 'Zend/Layout.php';
         $layout = Zend_Layout::getMvcInstance();
         if ($layout instanceof Zend_Layout) {
             $layout->disableLayout();
         }
     }
     $response = EvHttp_Controller_Front::getInstance()->getResponse();
     $response->setHeader('Content-Type', 'application/json');
     return $data->toJson();
 }
예제 #7
0
 /**
  * postDispatch() plugin hook -- check for exceptions and dispatch error
  * handler if necessary
  *
  * If the 'noErrorHandler' front controller flag has been set,
  * returns early.
  *
  * @param  EvHttp_Controller_Request_Abstract $request
  * @return void
  */
 public function postDispatch(EvHttp_Controller_Request_Abstract $request)
 {
     $frontController = EvHttp_Controller_Front::getInstance();
     if ($frontController->getParam('noErrorHandler')) {
         return;
     }
     $response = $this->getResponse();
     if ($this->_isInsideErrorHandlerLoop) {
         $exceptions = $response->getException();
         if (count($exceptions) > $this->_exceptionCountAtFirstEncounter) {
             // Exception thrown by error handler; tell the front controller to throw it
             $frontController->throwExceptions(true);
             throw array_pop($exceptions);
         }
     }
     // check for an exception AND allow the error handler controller the option to forward
     if ($response->isException() && !$this->_isInsideErrorHandlerLoop) {
         $this->_isInsideErrorHandlerLoop = true;
         // Get exception information
         $error = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
         $exceptions = $response->getException();
         $exception = $exceptions[0];
         $exceptionType = get_class($exception);
         $error->exception = $exception;
         switch ($exceptionType) {
             case 'EvHttp_Controller_Dispatcher_Exception':
                 $error->type = self::EXCEPTION_NO_CONTROLLER;
                 break;
             case 'EvHttp_Controller_Action_Exception':
                 if (404 == $exception->getCode()) {
                     $error->type = self::EXCEPTION_NO_ACTION;
                 } else {
                     $error->type = self::EXCEPTION_OTHER;
                 }
                 break;
             default:
                 $error->type = self::EXCEPTION_OTHER;
                 break;
         }
         // Keep a copy of the original request
         $error->request = clone $request;
         // get a count of the number of exceptions encountered
         $this->_exceptionCountAtFirstEncounter = count($exceptions);
         // Forward to the error handler
         $request->setParam('error_handler', $error)->setModuleName($this->getErrorHandlerModule())->setControllerName($this->getErrorHandlerController())->setActionName($this->getErrorHandlerAction())->setDispatched(false);
     }
 }
예제 #8
0
파일: Front.php 프로젝트: dreamsxin/Kellner
 /**
  * Singleton instance
  *
  * @return EvHttp_Controller_Front
  */
 public static function getInstance()
 {
     if (null === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
예제 #9
0
 /**
  * Retrieve Front Controller
  *
  * @return EvHttp_Controller_Front
  */
 public function getFrontController()
 {
     // Used cache version if found
     if (null !== $this->_frontController) {
         return $this->_frontController;
     }
     // Grab singleton instance, if class has been loaded
     if (class_exists('EvHttp_Controller_Front')) {
         $this->_frontController = EvHttp_Controller_Front::getInstance();
         return $this->_frontController;
     }
     // Throw exception in all other cases
     require_once 'EvHttp/Controller/Exception.php';
     throw new EvHttp_Controller_Exception('Front controller class has not been loaded');
 }
예제 #10
0
 /**
  * Called before EvHttp_Controller_Front exits its dispatch loop.
  *
  * @param  EvHttp_Controller_Request_Abstract $request
  * @return void
  */
 public function dispatchLoopShutdown()
 {
     foreach ($this->_plugins as $plugin) {
         try {
             $plugin->dispatchLoopShutdown();
         } catch (Exception $e) {
             if (EvHttp_Controller_Front::getInstance()->throwExceptions()) {
                 throw $e;
             } else {
                 $this->getResponse()->setException($e);
             }
         }
     }
 }
예제 #11
0
 /**
  * Retrieve Front Controller
  *
  * @return EvHttp_Controller_Front
  */
 public function getFrontController()
 {
     // Used cache version if found
     if (null !== $this->_frontController) {
         return $this->_frontController;
     }
     require_once 'EvHttp/Controller/Front.php';
     $this->_frontController = EvHttp_Controller_Front::getInstance();
     return $this->_frontController;
 }
예제 #12
0
 /**
  * Get the request object
  *
  * @return EvHttp_Controller_Request_Abstract $request
  */
 public function getRequest()
 {
     if ($this->_request === null) {
         require_once 'EvHttp/Controller/Front.php';
         $this->_request = EvHttp_Controller_Front::getInstance()->getRequest();
     }
     return $this->_request;
 }
예제 #13
0
 /**
  * Retrieve front controller instance
  *
  * @return EvHttp_Controller_Front
  */
 public function getFrontController()
 {
     if (null === $this->_frontController) {
         require_once 'EvHttp/Controller/Front.php';
         $this->_frontController = EvHttp_Controller_Front::getInstance();
     }
     return $this->_frontController;
 }