コード例 #1
0
ファイル: Front.php プロジェクト: jasmun/Noco100
 /**
  * Dispatch an HTTP request to a controller/action.
  *
  * @param IfwPsn_Vendor_Zend_Controller_Request_Abstract|null $request
  * @param IfwPsn_Vendor_Zend_Controller_Response_Abstract|null $response
  * @return void|IfwPsn_Vendor_Zend_Controller_Response_Abstract Returns response object if returnResponse() is true
  */
 public function dispatch(IfwPsn_Vendor_Zend_Controller_Request_Abstract $request = null, IfwPsn_Vendor_Zend_Controller_Response_Abstract $response = null)
 {
     if (!$this->getParam('noErrorHandler') && !$this->_plugins->hasPlugin('IfwPsn_Vendor_Zend_Controller_Plugin_ErrorHandler')) {
         // Register with stack index of 100
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Plugin/ErrorHandler.php';
         $this->_plugins->registerPlugin(new IfwPsn_Vendor_Zend_Controller_Plugin_ErrorHandler(), 100);
     }
     if (!$this->getParam('noViewRenderer') && !IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer')) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Action/Helper/ViewRenderer.php';
         IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStack()->offsetSet(-80, new IfwPsn_Vendor_Zend_Controller_Action_Helper_ViewRenderer());
     }
     /**
      * Instantiate default request object (HTTP version) if none provided
      */
     if (null !== $request) {
         $this->setRequest($request);
     } elseif (null === $request && null === ($request = $this->getRequest())) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Request/Http.php';
         $request = new IfwPsn_Vendor_Zend_Controller_Request_Http();
         $this->setRequest($request);
     }
     /**
      * Set base URL of request object, if available
      */
     if (is_callable(array($this->_request, 'setBaseUrl'))) {
         if (null !== $this->_baseUrl) {
             $this->_request->setBaseUrl($this->_baseUrl);
         }
     }
     /**
      * Instantiate default response object (HTTP version) if none provided
      */
     if (null !== $response) {
         $this->setResponse($response);
     } elseif (null === $this->_response && null === ($this->_response = $this->getResponse())) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Response/Http.php';
         $response = new IfwPsn_Vendor_Zend_Controller_Response_Http();
         $this->setResponse($response);
     }
     /**
      * Register request and response objects with plugin broker
      */
     $this->_plugins->setRequest($this->_request)->setResponse($this->_response);
     /**
      * Initialize router
      */
     $router = $this->getRouter();
     $router->setParams($this->getParams());
     /**
      * Initialize dispatcher
      */
     $dispatcher = $this->getDispatcher();
     $dispatcher->setParams($this->getParams())->setResponse($this->_response);
     // Begin dispatch
     try {
         /**
          * Route request to controller/action, if a router is provided
          */
         /**
          * Notify plugins of router startup
          */
         $this->_plugins->routeStartup($this->_request);
         try {
             $router->route($this->_request);
         } catch (Exception $e) {
             if ($this->throwExceptions()) {
                 throw $e;
             }
             $this->_response->setException($e);
         }
         /**
          * Notify plugins of router completion
          */
         $this->_plugins->routeShutdown($this->_request);
         /**
          * Notify plugins of dispatch loop startup
          */
         $this->_plugins->dispatchLoopStartup($this->_request);
         /**
          *  Attempt to dispatch the controller/action. If the $this->_request
          *  indicates that it needs to be dispatched, move to the next
          *  action in the request.
          */
         do {
             $this->_request->setDispatched(true);
             /**
              * Notify plugins of dispatch startup
              */
             $this->_plugins->preDispatch($this->_request);
             /**
              * Skip requested action if preDispatch() has reset it
              */
             if (!$this->_request->isDispatched()) {
                 continue;
             }
             /**
              * Dispatch request
              */
             try {
                 $dispatcher->dispatch($this->_request, $this->_response);
             } catch (Exception $e) {
                 if ($this->throwExceptions()) {
                     throw $e;
                 }
                 $this->_response->setException($e);
             }
             /**
              * Notify plugins of dispatch completion
              */
             $this->_plugins->postDispatch($this->_request);
         } while (!$this->_request->isDispatched());
     } catch (Exception $e) {
         if ($this->throwExceptions()) {
             throw $e;
         }
         $this->_response->setException($e);
     }
     /**
      * Notify plugins of dispatch loop completion
      */
     try {
         $this->_plugins->dispatchLoopShutdown();
     } catch (Exception $e) {
         if ($this->throwExceptions()) {
             throw $e;
         }
         $this->_response->setException($e);
     }
     if ($this->returnResponse()) {
         return $this->_response;
     }
     $this->_response->sendResponse();
 }
コード例 #2
0
ファイル: Action.php プロジェクト: jasmun/Noco100
 /**
  * Construct view script path
  *
  * Used by render() to determine the path to the view script.
  *
  * @param  string $action Defaults to action registered in request object
  * @param  bool $noController  Defaults to false; i.e. use controller name as subdir in which to search for view script
  * @return string
  * @throws IfwPsn_Vendor_Zend_Controller_Exception with bad $action
  */
 public function getViewScript($action = null, $noController = null)
 {
     if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
         $viewRenderer = $this->_helper->getHelper('viewRenderer');
         if (null !== $noController) {
             $viewRenderer->setNoController($noController);
         }
         return $viewRenderer->getViewScript($action);
     }
     $request = $this->getRequest();
     if (null === $action) {
         $action = $request->getActionName();
     } elseif (!is_string($action)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Exception.php';
         throw new IfwPsn_Vendor_Zend_Controller_Exception('Invalid action specifier for view render');
     }
     if (null === $this->_delimiters) {
         $dispatcher = IfwPsn_Vendor_Zend_Controller_Front::getInstance()->getDispatcher();
         $wordDelimiters = $dispatcher->getWordDelimiter();
         $pathDelimiters = $dispatcher->getPathDelimiter();
         $this->_delimiters = array_unique(array_merge($wordDelimiters, (array) $pathDelimiters));
     }
     $action = str_replace($this->_delimiters, '-', $action);
     $script = $action . '.' . $this->viewSuffix;
     if (!$noController) {
         $controller = $request->getControllerName();
         $controller = str_replace($this->_delimiters, '-', $controller);
         $script = $controller . DIRECTORY_SEPARATOR . $script;
     }
     return $script;
 }
コード例 #3
0
ファイル: Front.php プロジェクト: jasmun/Noco100
 /**
  * @param IfwPsn_Vendor_Zend_Controller_Request_Abstract $request
  * @param IfwPsn_Vendor_Zend_Controller_Response_Abstract $response
  * @throws Exception
  */
 public function initController(IfwPsn_Wp_Plugin_Manager $pm, IfwPsn_Vendor_Zend_Controller_Request_Abstract $request = null, IfwPsn_Vendor_Zend_Controller_Response_Abstract $response = null)
 {
     if (!$this->getParam('noErrorHandler') && !$this->_plugins->hasPlugin('IfwPsn_Vendor_Zend_Controller_Plugin_ErrorHandler')) {
         // Register with stack index of 100
         //require_once 'IfwZend/Controller/Plugin/ErrorHandler.php';
         $this->_plugins->registerPlugin(new IfwPsn_Vendor_Zend_Controller_Plugin_ErrorHandler(), 100);
     }
     if (!$this->getParam('noViewRenderer') && !IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer')) {
         //require_once 'IfwZend/Controller/Action/Helper/ViewRenderer.php';
         IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStack()->offsetSet(-80, new IfwPsn_Vendor_Zend_Controller_Action_Helper_ViewRenderer());
     }
     /**
      * Instantiate default request object (HTTP version) if none provided
      */
     if (null !== $request) {
         $this->setRequest($request);
     } elseif (null === $request && null === ($request = $this->getRequest())) {
         //require_once 'IfwZend/Controller/Request/Http.php';
         $request = new IfwPsn_Vendor_Zend_Controller_Request_Http();
         $this->setRequest($request);
     }
     $request->setActionKey($pm->getConfig()->getActionKey());
     /**
      * Set base URL of request object, if available
      */
     if (is_callable(array($this->_request, 'setBaseUrl'))) {
         if (null !== $this->_baseUrl) {
             $this->_request->setBaseUrl($this->_baseUrl);
         }
     }
     /**
      * Instantiate default response object (HTTP version) if none provided
      */
     if (null !== $response) {
         $this->setResponse($response);
     } elseif (null === $this->_response && null === ($this->_response = $this->getResponse())) {
         //require_once 'IfwZend/Controller/Response/Http.php';
         $response = new IfwPsn_Vendor_Zend_Controller_Response_Http();
         $this->setResponse($response);
     }
     //IfwPsn_Wp_Proxy_Action::doPlugin($pm, 'before_controller_init', $this);
     /**
      * Register request and response objects with plugin broker
      */
     $this->_plugins->setRequest($this->_request)->setResponse($this->_response);
     IfwPsn_Wp_Proxy_Action::doPlugin($pm, 'before_controller_init', $this);
     /**
      * Initialize router
      */
     $router = $this->getRouter();
     $router->setParams($this->getParams());
     /**
      * Initialize dispatcher
      */
     $dispatcher = $this->getDispatcher();
     $dispatcher->setParams($this->getParams())->setResponse($this->_response);
     // Begin dispatch
     try {
         /**
          * Route request to controller/action, if a router is provided
          */
         /**
          * Notify plugins of router startup
          */
         $this->_plugins->routeStartup($this->_request);
         try {
             $router->route($this->_request);
         } catch (Exception $e) {
             throw $e;
         }
         /**
          * Needed for custom route RequestVars
          */
         $this->_plugins->routeShutdown($this->_request);
         /**
          * skip plugins dispatchLoopStartup on initController
          */
         //$this->_plugins->dispatchLoopStartup($this->_request);
         /**
          *  Attempt to dispatch the controller/action. If the $this->_request
          *  indicates that it needs to be dispatched, move to the next
          *  action in the request.
          */
         do {
             $this->_request->setDispatched(true);
             /**
              * skip plugins preDispatch on initController
              */
             $this->_plugins->preDispatch($this->_request);
             /**
              * Skip requested action if preDispatch() has reset it
              */
             //if (!$this->_request->isDispatched()) {
             //    continue;
             //}
             /**
              * init controller
              */
             try {
                 // this will add custom WP action to the controller object
                 $dispatcher->initController($this->_request, $this->_response);
             } catch (Exception $e) {
                 throw $e;
             }
             /**
              * skip plugins postDispatch on initController
              */
             //$this->_plugins->postDispatch($this->_request);
         } while (!$this->_request->isDispatched());
     } catch (Exception $e) {
         throw $e;
     }
 }
コード例 #4
0
ファイル: Layout.php プロジェクト: jasmun/Noco100
 /**
  * Initialize action helper
  *
  * @return void
  */
 protected function _initHelper()
 {
     $helperClass = $this->getHelperClass();
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Action/HelperBroker.php';
     if (!IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::hasHelper('layout')) {
         if (!class_exists($helperClass)) {
             require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
             IfwPsn_Zend_Loader::loadClass($helperClass);
         }
         IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStack()->offsetSet(-90, new $helperClass($this));
     }
 }