コード例 #1
0
ファイル: PutHandler.php プロジェクト: jasmun/Noco100
 /**
  * Before dispatching, digest PUT request body and set params
  *
  * @param IfwPsn_Vendor_Zend_Controller_Request_Abstract $request
  */
 public function preDispatch(IfwPsn_Vendor_Zend_Controller_Request_Abstract $request)
 {
     if (!$request instanceof IfwPsn_Vendor_Zend_Controller_Request_Http) {
         return;
     }
     if ($this->_request->isPut()) {
         $putParams = array();
         parse_str($this->_request->getRawBody(), $putParams);
         $request->setParams($putParams);
     }
 }
コード例 #2
0
ファイル: Module.php プロジェクト: jasmun/Noco100
 /**
  * Set request keys based on values in request object
  *
  * @return void
  */
 protected function _setRequestKeys()
 {
     if (null !== $this->_request) {
         $this->_moduleKey = $this->_request->getModuleKey();
         $this->_controllerKey = $this->_request->getControllerKey();
         $this->_actionKey = $this->_request->getActionKey();
     }
     if (null !== $this->_dispatcher) {
         $this->_defaults += array($this->_controllerKey => $this->_dispatcher->getDefaultControllerName(), $this->_actionKey => $this->_dispatcher->getDefaultAction(), $this->_moduleKey => $this->_dispatcher->getDefaultModule());
     }
     $this->_keysSet = true;
 }
コード例 #3
0
ファイル: Action.php プロジェクト: jasmun/Noco100
 /**
  * Retrieve rendered contents of a controller action
  *
  * If the action results in a forward or redirect, returns empty string.
  *
  * @param  string $action
  * @param  string $controller
  * @param  string $module Defaults to default module
  * @param  array $params
  * @return string
  */
 public function action($action, $controller, $module = null, array $params = array())
 {
     $this->resetObjects();
     if (null === $module) {
         $module = $this->defaultModule;
     }
     // clone the view object to prevent over-writing of view variables
     $viewRendererObj = IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
     IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::addHelper(clone $viewRendererObj);
     $this->request->setParams($params)->setModuleName($module)->setControllerName($controller)->setActionName($action)->setDispatched(true);
     $this->dispatcher->dispatch($this->request, $this->response);
     // reset the viewRenderer object to it's original state
     IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::addHelper($viewRendererObj);
     if (!$this->request->isDispatched() || $this->response->isRedirect()) {
         // forwards and redirects render nothing
         return '';
     }
     $return = $this->response->getBody();
     $this->resetObjects();
     return $return;
 }
コード例 #4
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();
 }
コード例 #5
0
ファイル: ErrorHandler.php プロジェクト: jasmun/Noco100
 /**
  * Handle errors and exceptions
  *
  * If the 'noErrorHandler' front controller flag has been set,
  * returns early.
  *
  * @param  IfwPsn_Vendor_Zend_Controller_Request_Abstract $request
  * @return void
  */
 protected function _handleError(IfwPsn_Vendor_Zend_Controller_Request_Abstract $request)
 {
     $frontController = IfwPsn_Vendor_Zend_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 'IfwPsn_Vendor_Zend_Controller_Router_Exception':
                 if (404 == $exception->getCode()) {
                     $error->type = self::EXCEPTION_NO_ROUTE;
                 } else {
                     $error->type = self::EXCEPTION_OTHER;
                 }
                 break;
             case 'IfwPsn_Vendor_Zend_Controller_Dispatcher_Exception':
                 $error->type = self::EXCEPTION_NO_CONTROLLER;
                 break;
             case 'IfwPsn_Vendor_Zend_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);
     }
 }
コード例 #6
0
ファイル: Wp.php プロジェクト: jasmun/Noco100
 /**
  * Dispatch to a controller/action
  *
  * By default, if a controller is not dispatchable, dispatch() will throw
  * an exception. If you wish to use the default controller instead, set the
  * param 'useDefaultControllerAlways' via {@link setParam()}.
  *
  * @param IfwPsn_Vendor_Zend_Controller_Request_Abstract $request
  * @param IfwPsn_Vendor_Zend_Controller_Response_Abstract $response
  * @throws IfwPsn_Vendor_Zend_Controller_Dispatcher_Exception
  * @throws Exception
  * @return void
  */
 public function dispatch(IfwPsn_Vendor_Zend_Controller_Request_Abstract $request, IfwPsn_Vendor_Zend_Controller_Response_Abstract $response)
 {
     $this->setResponse($response);
     if (!$this->_controller instanceof IfwPsn_Vendor_Zend_Controller_Action_Interface or !strpos(strtolower($request->getControllerName()), strtolower($request->get('controller')))) {
         // if controller is not initialized by initController already or on error/excption
         /**
          * Get controller class
          */
         if (!$this->isDispatchable($request)) {
             $controller = $request->getControllerName();
             if (!$this->getParam('useDefaultControllerAlways') && !empty($controller)) {
                 //require_once 'IfwZend/Controller/Dispatcher/Exception.php';
                 throw new IfwPsn_Vendor_Zend_Controller_Dispatcher_Exception('Invalid controller specified (' . $request->getControllerName() . ')');
             }
             $className = $this->getDefaultControllerClass($request);
         } else {
             $className = $this->getControllerClass($request);
             if (!$className) {
                 $className = $this->getDefaultControllerClass($request);
             }
         }
         /**
          * Load the controller class file
          */
         $className = $this->loadClass($className);
         /**
          * Instantiate controller with request, response, and invocation
          * arguments; throw exception if it's not an action controller
          */
         $this->_controller = new $className($request, $this->getResponse(), $this->getParams());
         if (!$this->_controller instanceof IfwPsn_Vendor_Zend_Controller_Action_Interface && !$this->_controller instanceof IfwPsn_Vendor_Zend_Controller_Action) {
             //require_once 'IfwZend/Controller/Dispatcher/Exception.php';
             throw new IfwPsn_Vendor_Zend_Controller_Dispatcher_Exception('Controller "' . $className . '" is not an instance of IfwPsn_Vendor_Zend_Controller_Action_Interface');
         }
     }
     /**
      * Retrieve the action name
      */
     $action = $this->getActionMethod($request);
     /**
      * Dispatch the method call
      */
     $request->setDispatched(true);
     // by default, buffer output
     $disableOb = $this->getParam('disableOutputBuffering');
     $obLevel = ob_get_level();
     if (empty($disableOb)) {
         ob_start();
     }
     try {
         $this->_pm->getLogger()->logPrefixed(sprintf('Dispatching action %s on controller %s', $action, get_class($this->_controller)));
         $this->_controller->dispatch($action);
     } catch (Exception $e) {
         // Clean output buffer on error
         $curObLevel = ob_get_level();
         if ($curObLevel > $obLevel) {
             do {
                 ob_get_clean();
                 $curObLevel = ob_get_level();
             } while ($curObLevel > $obLevel);
         }
         throw $e;
     }
     if (empty($disableOb)) {
         $content = ob_get_clean();
         $response->appendBody($content);
     }
     // Destroy the page controller instance and reflection objects
     $this->_controller = null;
 }
コード例 #7
0
ファイル: Layout.php プロジェクト: jasmun/Noco100
 /**
  * postDispatch() plugin hook -- render layout
  *
  * @param  IfwPsn_Vendor_Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function postDispatch(IfwPsn_Vendor_Zend_Controller_Request_Abstract $request)
 {
     $layout = $this->getLayout();
     $helper = $this->getLayoutActionHelper();
     // Return early if forward detected
     if (!$request->isDispatched() || $this->getResponse()->isRedirect() || $layout->getMvcSuccessfulActionOnly() && (!empty($helper) && !$helper->isActionControllerSuccessful())) {
         return;
     }
     // Return early if layout has been disabled
     if (!$layout->isEnabled()) {
         return;
     }
     $response = $this->getResponse();
     $content = $response->getBody(true);
     $contentKey = $layout->getContentKey();
     if (isset($content['default'])) {
         $content[$contentKey] = $content['default'];
     }
     if ('default' != $contentKey) {
         unset($content['default']);
     }
     $layout->assign($content);
     $fullContent = null;
     $obStartLevel = ob_get_level();
     try {
         $fullContent = $layout->render();
         $response->setBody($fullContent);
     } catch (Exception $e) {
         while (ob_get_level() > $obStartLevel) {
             $fullContent .= ob_get_clean();
         }
         $request->setParam('layoutFullContent', $fullContent);
         $request->setParam('layoutContent', $layout->content);
         $response->setBody(null);
         throw $e;
     }
 }
コード例 #8
0
 /**
  * Retrieves custom controller name
  *  
  * @param IfwPsn_Vendor_Zend_Controller_Request_Abstract $request
  * @return string|boolean
  */
 protected function _getCustomController($request)
 {
     $controllerName = $this->_pm->getAbbr() . '-' . $request->get('controller');
     return $controllerName;
 }
コード例 #9
0
ファイル: ActionStack.php プロジェクト: jasmun/Noco100
 /**
  * Forward request with next action
  *
  * @param  array $next
  * @return void
  */
 public function forward(IfwPsn_Vendor_Zend_Controller_Request_Abstract $next)
 {
     $request = $this->getRequest();
     if ($this->getClearRequestParams()) {
         $request->clearParams();
     }
     $request->setModuleName($next->getModuleName())->setControllerName($next->getControllerName())->setActionName($next->getActionName())->setParams($next->getParams())->setDispatched(false);
 }
コード例 #10
0
ファイル: Rewrite.php プロジェクト: jasmun/Noco100
 /**
  * Find a matching route to the current PATH_INFO and inject
  * returning values to the Request object.
  *
  * @throws IfwPsn_Vendor_Zend_Controller_Router_Exception
  * @return IfwPsn_Vendor_Zend_Controller_Request_Abstract Request object
  */
 public function route(IfwPsn_Vendor_Zend_Controller_Request_Abstract $request)
 {
     if (!$request instanceof IfwPsn_Vendor_Zend_Controller_Request_Http) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Router/Exception.php';
         throw new IfwPsn_Vendor_Zend_Controller_Router_Exception('IfwPsn_Vendor_Zend_Controller_Router_Rewrite requires a IfwPsn_Vendor_Zend_Controller_Request_Http-based request object');
     }
     if ($this->_useDefaultRoutes) {
         $this->addDefaultRoutes();
     }
     // Find the matching route
     $routeMatched = false;
     foreach (array_reverse($this->_routes, true) as $name => $route) {
         // TODO: Should be an interface method. Hack for 1.0 BC
         if (method_exists($route, 'isAbstract') && $route->isAbstract()) {
             continue;
         }
         // TODO: Should be an interface method. Hack for 1.0 BC
         if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) {
             $match = $request->getPathInfo();
         } else {
             $match = $request;
         }
         if ($params = $route->match($match)) {
             $this->_setRequestParams($request, $params);
             $this->_currentRoute = $name;
             $routeMatched = true;
             break;
         }
     }
     if (!$routeMatched) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Router/Exception.php';
         throw new IfwPsn_Vendor_Zend_Controller_Router_Exception('No route matched the request', 404);
     }
     if ($this->_useCurrentParamsAsGlobal) {
         $params = $request->getParams();
         foreach ($params as $param => $value) {
             $this->setGlobalParam($param, $value);
         }
     }
     return $request;
 }
コード例 #11
0
ファイル: Default.php プロジェクト: jasmun/Noco100
 /**
  * @param string $name
  * @param array $arguments
  */
 public function __call($name, $arguments)
 {
     $controller = $this->_request->get('controller');
     $controller = esc_attr($controller);
     IfwPsn_Wp_Proxy_Action::doAction($this->_pm->getAbbrLower() . '_' . $controller . '_action-' . str_replace('Action', '', $name), $this, $arguments);
 }
コード例 #12
0
ファイル: Http.php プロジェクト: jasmun/Noco100
 /**
  * Set a userland parameter
  *
  * Uses $key to set a userland parameter. If $key is an alias, the actual
  * key will be retrieved and used to set the parameter.
  *
  * @param mixed $key
  * @param mixed $value
  * @return IfwPsn_Vendor_Zend_Controller_Request_Http
  */
 public function setParam($key, $value)
 {
     $key = null !== ($alias = $this->getAlias($key)) ? $alias : $key;
     parent::setParam($key, $value);
     return $this;
 }