/** * Defined by IfwPsn_Vendor_Zend_Application_Resource_Resource * * @return IfwPsn_Vendor_Zend_View */ public function init() { $view = $this->getView(); $viewRenderer = IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $viewRenderer->setView($view); return $view; }
/** * Create JSON response * * Encodes and returns data to JSON. Content-Type header set to * 'application/json', and disables layouts and viewRenderer (if being * used). * * @param mixed $data * @param boolean $keepLayouts * @param boolean|array $keepLayouts * @param boolean $encodeData Provided data is already JSON * NOTE: if boolean, establish $keepLayouts to true|false * if array, admit params for IfwPsn_Vendor_Zend_Json::encode as enableJsonExprFinder=>true|false * if $keepLayouts and parmas for IfwPsn_Vendor_Zend_Json::encode are required * then, the array can contains a 'keepLayout'=>true|false and/or 'encodeData'=>true|false * that will not be passed to IfwPsn_Vendor_Zend_Json::encode method but will be passed * to IfwPsn_Vendor_Zend_View_Helper_Json * @throws IfwPsn_Vendor_Zend_Controller_Action_Helper_Json * @return string */ public function encodeJson($data, $keepLayouts = false, $encodeData = true) { /** * @see IfwPsn_Vendor_Zend_View_Helper_Json */ require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/View/Helper/Json.php'; $jsonHelper = new IfwPsn_Vendor_Zend_View_Helper_Json(); $data = $jsonHelper->json($data, $keepLayouts, $encodeData); if (!$keepLayouts) { /** * @see IfwPsn_Vendor_Zend_Controller_Action_HelperBroker */ require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Action/HelperBroker.php'; IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true); } return $data; }
/** * Returns href for this page * * This method uses {@link IfwPsn_Vendor_Zend_Controller_Action_Helper_Url} to assemble * the href based on the page's properties. * * @return string page href */ public function getHref() { if ($this->_hrefCache) { return $this->_hrefCache; } if (null === self::$_urlHelper) { self::$_urlHelper = IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('Url'); } $params = $this->getParams(); if ($param = $this->getModule()) { $params['module'] = $param; } if ($param = $this->getController()) { $params[IfwPsn_Zend_Controller_Front::getInstance()->getRequest()->getControllerKey()] = $param; } if ($param = $this->getAction()) { $params[IfwPsn_Zend_Controller_Front::getInstance()->getRequest()->getActionKey()] = $param; } if ($param = $this->getPage()) { $params['page'] = $param; } if ($param = $this->getAdminpage()) { $params['adminpage'] = $param; } if ($param = $this->getEditpage()) { $params['editpage'] = $param; } if ($param = $this->getPosttype()) { $params['posttype'] = $param; } $url = self::$_urlHelper->url($params, $this->getRoute(), $this->getResetParams(), $this->getEncodeUrl()); // Add the fragment identifier if it is set $fragment = $this->getFragment(); if (null !== $fragment) { $url .= '#' . $fragment; } return $this->_hrefCache = $url; }
/** * Prepare data for autocompletion * * @param mixed $data * @param boolean $keepLayouts * @return string */ public function prepareAutoCompletion($data, $keepLayouts = false) { if (!$data instanceof IfwPsn_Vendor_Zend_Dojo_Data) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Dojo/Data.php'; $items = array(); foreach ($data as $key => $value) { $items[] = array('label' => $value, 'name' => $value); } $data = new IfwPsn_Vendor_Zend_Dojo_Data('name', $items); } if (!$keepLayouts) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Action/HelperBroker.php'; IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true); require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Layout.php'; $layout = IfwPsn_Vendor_Zend_Layout::getMvcInstance(); if ($layout instanceof IfwPsn_Vendor_Zend_Layout) { $layout->disableLayout(); } } $response = IfwPsn_Vendor_Zend_Controller_Front::getInstance()->getResponse(); $response->setHeader('Content-Type', 'application/json'); return $data->toJson(); }
/** * 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(); }
/** * Returns href for this page * * This method uses {@link IfwPsn_Vendor_Zend_Controller_Action_Helper_Url} to assemble * the href based on the page's properties. * * @return string page href */ public function getHref() { if ($this->_hrefCache) { return $this->_hrefCache; } if (null === self::$_urlHelper) { self::$_urlHelper = IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('Url'); } $params = $this->getParams(); if ($param = $this->getModule()) { $params['module'] = $param; } if ($param = $this->getController()) { $params['controller'] = $param; } if ($param = $this->getAction()) { $params['action'] = $param; } $url = self::$_urlHelper->url($params, $this->getRoute(), $this->getResetParams(), $this->getEncodeUrl()); // Use scheme? $scheme = $this->getScheme(); if (null !== $scheme) { if (null === self::$_schemeHelper) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/View/Helper/ServerUrl.php'; self::$_schemeHelper = new IfwPsn_Vendor_Zend_View_Helper_ServerUrl(); } $url = self::$_schemeHelper->setScheme($scheme)->serverUrl($url); } // Add the fragment identifier if it is set $fragment = $this->getFragment(); if (null !== $fragment) { $url .= '#' . $fragment; } return $this->_hrefCache = $url; }
/** * @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; } }
/** * Retrieve ViewRenderer * * @return IfwPsn_Vendor_Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface */ protected function _getViewRenderer() { if (null === $this->_viewRenderer) { $this->_viewRenderer = IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); } return $this->_viewRenderer; }
/** * 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; }
/** * Initialize Front Controller * * @return IfwPsn_Vendor_Zend_Controller_Front */ public function init() { $front = $this->getFrontController(); foreach ($this->getOptions() as $key => $value) { switch (strtolower($key)) { case 'controllerdirectory': if (is_string($value)) { $front->setControllerDirectory($value); } elseif (is_array($value)) { foreach ($value as $module => $directory) { $front->addControllerDirectory($directory, $module); } } break; case 'modulecontrollerdirectoryname': $front->setModuleControllerDirectoryName($value); break; case 'moduledirectory': if (is_string($value)) { $front->addModuleDirectory($value); } elseif (is_array($value)) { foreach ($value as $moduleDir) { $front->addModuleDirectory($moduleDir); } } break; case 'defaultcontrollername': $front->setDefaultControllerName($value); break; case 'defaultaction': $front->setDefaultAction($value); break; case 'defaultmodule': $front->setDefaultModule($value); break; case 'baseurl': if (!empty($value)) { $front->setBaseUrl($value); } break; case 'params': $front->setParams($value); break; case 'plugins': foreach ((array) $value as $pluginClass) { $stackIndex = null; if (is_array($pluginClass)) { $pluginClass = array_change_key_case($pluginClass, CASE_LOWER); if (isset($pluginClass['class'])) { if (isset($pluginClass['stackindex'])) { $stackIndex = $pluginClass['stackindex']; } $pluginClass = $pluginClass['class']; } } $plugin = new $pluginClass(); $front->registerPlugin($plugin, $stackIndex); } break; case 'returnresponse': $front->returnResponse((bool) $value); break; case 'throwexceptions': $front->throwExceptions((bool) $value); break; case 'actionhelperpaths': if (is_array($value)) { foreach ($value as $helperPrefix => $helperPath) { IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::addPath($helperPath, $helperPrefix); } } break; case 'dispatcher': if (!isset($value['class'])) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Application/Exception.php'; throw new IfwPsn_Vendor_Zend_Application_Exception('You must specify both '); } if (!isset($value['params'])) { $value['params'] = array(); } $dispatchClass = $value['class']; if (!class_exists($dispatchClass)) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Application/Exception.php'; throw new IfwPsn_Vendor_Zend_Application_Exception('Dispatcher class not found!'); } $front->setDispatcher(new $dispatchClass((array) $value['params'])); break; default: $front->setParam($key, $value); break; } } if (null !== ($bootstrap = $this->getBootstrap())) { $this->getBootstrap()->frontController = $front; } return $front; }
/** * Retrieve view * * @return IfwPsn_Vendor_Zend_View_Interface */ public function getView() { if (null === $this->_view) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Action/HelperBroker.php'; $viewRenderer = IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $this->setView($viewRenderer->view); } return $this->_view; }
/** * Encode data to JSON * * @param mixed $data * @param bool $keepLayouts * @throws IfwPsn_Vendor_Zend_Controller_Action_Exception * @return string */ public function encodeJson($data, $keepLayouts = false) { if ($this->validateData($data)) { return IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('Json')->encodeJson($data, $keepLayouts); } /** * @see IfwPsn_Vendor_Zend_Controller_Action_Exception */ require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Action/Exception.php'; throw new IfwPsn_Vendor_Zend_Controller_Action_Exception('Invalid data passed for autocompletion'); }
/** * Dispatch the requested action * * @param string $action Method name of action * @return void */ public function dispatch($action) { // Notify helpers of action preDispatch state $this->_helper->notifyPreDispatch(); $this->preDispatch(); if ($this->getRequest()->isDispatched()) { if (null === $this->_classMethods) { $this->_classMethods = get_class_methods($this); } // If pre-dispatch hooks introduced a redirect then stop dispatch // @see ZF-7496 if (!$this->getResponse()->isRedirect()) { // preDispatch() didn't change the action, so we can continue if ($this->getInvokeArg('useCaseSensitiveActions') || in_array($action, $this->_classMethods)) { if ($this->getInvokeArg('useCaseSensitiveActions')) { trigger_error('Using case sensitive actions without word separators is deprecated; please do not rely on this "feature"'); } $this->{$action}(); } else { $this->__call($action, array()); } } $this->postDispatch(); } // whats actually important here is that this action controller is // shutting down, regardless of dispatching; notify the helpers of this // state $this->_helper->notifyPostDispatch(); }
/** * Lazy load the priority stack and return it * * @return IfwPsn_Vendor_Zend_Controller_Action_HelperBroker_PriorityStack */ public static function getStack() { if (self::$_stack == null) { self::$_stack = new IfwPsn_Vendor_Zend_Controller_Action_HelperBroker_PriorityStack(); } return self::$_stack; }