Пример #1
0
 public function testShouldAllowAccessForCorrectRole()
 {
     $request = $this->request->setModuleName('admin')->setControllerName('index')->setActionName('index');
     $this->acl->addResource('admin_index');
     $this->acl->allow(Acl::ROLE_GUEST, 'admin_index');
     $plugin = new Acl($this->acl);
     $plugin->setRequest($this->request);
     $plugin->preDispatch();
     $this->assertEquals('admin', $this->request->getModuleName());
     $this->assertEquals('index', $this->request->getControllerName());
     $this->assertEquals('index', $this->request->getActionName());
 }
Пример #2
0
 /**
  * Called before an action is dispatched by Zend_Controller_Dispatcher.
  *
  * This callback allows for proxy or filter behavior.  The
  * $action must be returned for the Zend_Controller_Dispatcher_Token to be dispatched.
  * To abort the dispatch, return FALSE.
  *
  * @param  Zend_Controller_Request_Http $action
  * @return Zend_Controller_Dispatcher_Token|boolean
  */
 public function preDispatch($action)
 {
     $module = $action->getModuleName();
     $definition = null;
     if (isset($this->config[$module])) {
         $definition = $this->config[$module];
     } else {
         if (isset($this->config['master_layout'])) {
             $definition = $this->config['master_layout'];
         }
     }
     if ($definition != null && !$action->getParam('__ignorelayout')) {
         $view = null;
         $layoutName = $this->getViewNameFrom($definition, strtolower($action->getControllerName()), strtolower($action->getActionName()));
         if ($layoutName) {
             $view = new MasterView($layoutName, $this->config['layout_path']);
         }
         if ($view != null) {
             Zend_Registry::set('MasterView', $view);
             $baseView = Zend_Registry::get(NovemberApplication::$ZEND_VIEW);
             $baseView->setMaster('MasterView');
         }
     }
     return $action;
 }
Пример #3
0
 /**
  * Checks if site is active for the current request
  * 
  * @param bool $checkSubs  [optional] whether site should be considered
  *                         active if a subsite is active, default is false
  * @return bool
  */
 public function isActive($checkSubs = false)
 {
     if (isset($this->uri)) {
         // when uri is set, it is considered to be off-site
         return false;
     }
     
     if (null == self::$_request) {
         self::$_request = Zend_Controller_Front::getInstance()->getRequest();
     }
     
     $reqModule = self::$_request->getModuleName();
     $reqController = self::$_request->getControllerName();
     $reqAction = self::$_request->getActionName();
     
     if ($this->module == $reqModule &&
         $this->controller == $reqController &&
         $this->action == $reqAction) {
             return true;
     }
     
     if ($checkSubs && $this->hasSubSites()) {
         foreach ($this->_subSites as $id => $subSite) {
             if ($subSite->isActive(true)) {
                 return true;
             }
         }
     }
     
     return false;
 }
Пример #4
0
 public function testPostDispatchWithoutException()
 {
     $this->request->setModuleName('foo')->setControllerName('bar')->setActionName('baz');
     $this->plugin->postDispatch($this->request);
     $this->assertEquals('baz', $this->request->getActionName());
     $this->assertEquals('bar', $this->request->getControllerName());
     $this->assertEquals('foo', $this->request->getModuleName());
 }
Пример #5
0
 public function testPreDispatchNonWhitelistedActionWithAuthenticatedSession()
 {
     $this->request->setModuleName('default')->setControllerName('foo')->setActionName('home');
     Zend_Auth::getInstance()->getStorage()->write(true);
     $this->plugin->preDispatch($this->request);
     $this->assertEquals('default', $this->request->getModuleName());
     $this->assertEquals('foo', $this->request->getControllerName());
     $this->assertEquals('home', $this->request->getActionName());
 }
Пример #6
0
 /**
  * Create requested module's options from the requested
  * module's module.ini.
  * Router resource can only be defined in application.ini.
  * 
  * @return array
  */
 private function _getModuleOptions()
 {
     $moduleName = $this->_request->getModuleName();
     $moduleDir = $this->_moduleDir;
     $modConfig = $moduleDir . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR . 'module.ini';
     $options = $this->_loadConfig($modConfig);
     if (isset($options['resources']['router'])) {
         throw new Exception('You can only set routes in application.ini');
     }
     return $options;
 }
Пример #7
0
 /**
  * Parse more Zend_Controller_Request->getPathInfo()
  * @param Zend_Controller_Request_Http $request
  * @static
  * @return boolean
  */
 public static function getPathParts($request)
 {
     $pathParts = $request->getParams();
     l($pathParts, __METHOD__ . ' $request->getParams()', Zend_Log::DEBUG);
     $pathParts['host'] = (!empty($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']) . "/";
     // SERVER_NAME?
     $pathParts['module'] = $request->getModuleName();
     /* 		$pathParts = array(
     			'host' => (!empty($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']) . "/", // SERVER_NAME?
     			'module' => $request->getModuleName(),
     			'controller' => $request->getParam('controller'), // AKA $request->getControllerName()
     			'action' => $request->getParam('action'), // AKA $request->getActionName()
     			'id' => $request->getParam('id'), // since 5/7/2009 (WAS @deprecated, moved into Zx_IndexController)
     			'page' => $request->getParam('page') // since 5/7/2009 (WAS @deprecated, moved into Zx_IndexController)
     		);
      */
     // pre-router data @deprecated, use Zend_Controller_Router_Route for route rules!
     /* 		$s = substr($_SERVER['REQUEST_URI'], 1, -1);
     		$a = explode('/', $s);
     		$pathParts['controller0'] = $a[0];
     		if (count($a) > 1) {
     			$pathParts['action0'] = $a[1];
     		}
     */
     $prefix = self::getHttpPrefix();
     $pathParts['path'] = $pathParts['controller'] . "/" . ($pathParts['action'] == 'index' ? '' : $pathParts['action'] . "/");
     $pathParts['hostpath'] = $pathParts['host'] . $pathParts['path'];
     $pathParts['url'] = $prefix . $pathParts['path'];
     $pathParts['urlController'] = $prefix . $pathParts['controller'] . "/";
     // controller only
     Zend_Registry::set('path', $pathParts);
     Zend_Registry::set('page', isset($pathParts['page']) ? $pathParts['page'] : 1);
     // set to 1 if non-exists
     #echo "DEBUG:<br><textarea rows=10 cols=100>" . print_r($pathParts, 1) . "</textarea><br>";die;
     /* Array
     (
         [host] => il
         [module] => default
         [controller] => index
         [action] => index
         [id] =>
         [url] => http://il/index/index/
     )
     */
     return $pathParts;
 }
 /**
  * @param Zend_Controller_Request_Http $request
  * @return null|string
  */
 public function adCampaignBanner(Zend_Controller_Request_Http $request)
 {
     // Get module name from request
     $module = $request->getModuleName();
     // Set or get campaign and content details in session, if any
     $session = new Zend_Session_Namespace('homelet_global');
     if ($request->getParam('utm_campaign') != '') {
         $session->campaign = $request->getParam('utm_campaign');
     }
     if ($request->getParam('utm_content') != '') {
         $session->content = $request->getParam('utm_content');
     }
     $this->campaign = $session->campaign;
     $this->content = $session->content;
     // Look up to see if there's a match between module, campaign and content.
     if (isset($this->bannerMappings[$module][$this->campaign][$this->content])) {
         // Pass the matching parameters to the partial view to display
         $params = $this->bannerMappings[$module][$this->campaign][$this->content];
         return $this->view->partial('partials/ad-campaign-banner.phtml', $params);
     } else {
         // No match, no banner
         return null;
     }
 }
Пример #9
0
 public function match(Zend_Controller_Request_Http $request)
 {
     //checkings before even try to findout that current module should use this router
     if (!$this->_beforeModuleMatch()) {
         return false;
     }
     $this->fetchDefault();
     $front = $this->getFront();
     $p = explode('/', trim($request->getPathInfo(), '/'));
     // get module name
     if ($request->getModuleName()) {
         $module = $request->getModuleName();
     } else {
         if (!empty($p[0])) {
             $module = $p[0];
         } else {
             $module = $this->getFront()->getDefault('module');
             $request->setAlias('rewrite_request_path', '');
         }
     }
     if (!$module) {
         if (App_Main::isAdmin()) {
             $module = 'admin';
         }
     }
     if (empty($module)) {
         return false;
     }
     // Searching router args by module name from route using it as key
     $modules = $this->getModuleByFrontName($module);
     // If we did not found anything  we searching exact this module name in array values
     if ($modules === false) {
         if ($moduleFrontName = $this->getModuleByName($module, $this->_modules)) {
             $modules = array($module);
             $module = $moduleFrontName;
         }
     }
     if (empty($modules)) {
         return false;
     }
     /**
      * Going through modules to find appropriate controller
      */
     $found = false;
     foreach ($modules as $realModule) {
         $request->setRouteName($this->getRouteByFrontName($module));
         // get controller name
         if ($request->getControllerName()) {
             $controller = $request->getControllerName();
         } else {
             if (!empty($p[1])) {
                 $controller = $p[1];
             } else {
                 $controller = $front->getDefault('controller');
                 $request->setAlias('rewrite_request_path', ltrim($request->getOriginalPathInfo(), '/'));
             }
         }
         // get action name
         if (empty($action)) {
             if ($request->getActionName()) {
                 $action = $request->getActionName();
             } else {
                 $action = !empty($p[2]) ? $p[2] : $front->getDefault('action');
             }
         }
         //checking if this place should be secure
         $this->_checkShouldBeSecure($request, '/' . $module . '/' . $controller . '/' . $action);
         $controllerClassName = $this->_validateControllerClassName($realModule, $controller);
         if (!$controllerClassName) {
             continue;
         }
         // instantiate controller class
         $controllerInstance = new $controllerClassName($request, $front->getResponse());
         if (!$controllerInstance->hasAction($action)) {
             continue;
         }
         $found = true;
         break;
     }
     /**
      * if we did not found any siutibul
      */
     if (!$found) {
         if ($this->_noRouteShouldBeApplied()) {
             $controller = 'index';
             $action = 'noroute';
             $controllerClassName = $this->_validateControllerClassName($realModule, $controller);
             if (!$controllerClassName) {
                 return false;
             }
             // instantiate controller class
             $controllerInstance = new $controllerClassName($request, $front->getResponse());
             if (!$controllerInstance->hasAction($action)) {
                 return false;
             }
         } else {
             return false;
         }
     }
     // set values only after all the checks are done
     $request->setModuleName($module);
     $request->setControllerName($controller);
     $request->setActionName($action);
     $request->setControllerModule($realModule);
     // set parameters from pathinfo
     for ($i = 3, $l = sizeof($p); $i < $l; $i += 2) {
         $request->setParam($p[$i], isset($p[$i + 1]) ? $p[$i + 1] : '');
     }
     // dispatch action
     $request->setDispatched(true);
     $controllerInstance->dispatch($action);
     return true;
 }
Пример #10
0
 /**
  * Get specific request processor based on request parameters.
  *
  * @param Zend_Controller_Request_Http $request
  * @return Enterprise_PageCache_Model_Processor_Default
  */
 public function getRequestProcessor(Zend_Controller_Request_Http $request)
 {
     $processor = false;
     $configuration = Mage::getConfig()->getNode(self::XML_NODE_ALLOWED_CACHE);
     if ($configuration) {
         $configuration = $configuration->asArray();
     }
     $module = $request->getModuleName();
     if (isset($configuration[$module])) {
         $model = $configuration[$module];
         $controller = $request->getControllerName();
         if (is_array($configuration[$module]) && isset($configuration[$module][$controller])) {
             $model = $configuration[$module][$controller];
             $action = $request->getActionName();
             if (is_array($configuration[$module][$controller]) && isset($configuration[$module][$controller][$action])) {
                 $model = $configuration[$module][$controller][$action];
             }
         }
         if (is_string($model)) {
             $processor = Mage::getModel($model);
         }
     }
     return $processor;
 }
Пример #11
0
 /**
  * Retrieve the module name
  *
  * @return string
  */
 public function getModuleName()
 {
     return ucfirst(System_String::StrToLower(parent::getModuleName()));
 }
Пример #12
0
 /**
  * Log a message showing a reroute.
  * 
  * @param  Zend_Controller_Request_Http  $request
  * @param  Zend_Config|array  $rerouteTo   where to reroute the request to
  * @return void
  */
 public static function logReroute(Zend_Controller_Request_Http $request, $rerouteTo, $reason)
 {
     if ($rerouteTo instanceof Zend_Config) {
         $reroute = $rerouteTo->toArray();
     } else {
         $reroute = $rerouteTo;
     }
     self::log('Reroute from URI: ' . $request->getRequestUri() . ' (' . $request->getModuleName() . '/' . $request->getControllerName() . '/' . $request->getActionName() . '/' . ') to: ' . $reroute['moduleName'] . '/' . $reroute['controllerName'] . '/' . $reroute['actionName'] . " Reason: {$reason}");
 }
Пример #13
0
 /**
  * Called before an action is dispatched by Zend_Controller_Dispatcher.
  *
  * This callback allows for proxy or filter behavior.  The
  * $action must be returned for the Zend_Controller_Dispatcher_Token to be dispatched.
  * To abort the dispatch, return FALSE.
  *
  * @param  Zend_Controller_Request_Http $action
  * @return Zend_Controller_Request_Http
  */
 public function preDispatch($action)
 {
     /*@var $action Zend_Controller_Request_Http */
     $controllerName = strtolower($action->getControllerName());
     $actionName = strtolower($action->getActionName());
     $moduleName = strtolower($action->getModuleName());
     // Check for authorization.
     $app = NovemberApplication::getInstance();
     $currentUser = $app->getUser();
     if ($currentUser->getRole() == User::ROLE_LOCKED) {
         $action->setControllerName(ifset($this->config, 'login_controller', 'user'));
         $action->setActionName(ifset($this->config, 'login_action', 'login'));
         return $action;
     }
     // Get the restrictions for the current request (if any)
     $conf = ifset($this->config, $moduleName);
     $roles = '';
     if (is_string($conf)) {
         $roles = $conf;
     } else {
         if (is_array($conf)) {
             // check for a default
             $roles = ifset($conf, 'default_roles', '');
             // If there's something in the controllername entry...
             $controllerConf = ifset($conf, $controllerName, $roles);
             if (is_array($controllerConf)) {
                 $roles = ifset($controllerConf, $actionName, $roles);
             } else {
                 $roles = $controllerConf;
             }
         }
     }
     // Are there required roles to authenticate?
     $loginRequired = false;
     za()->log(__CLASS__ . ':' . __LINE__ . " - Authorizing " . $currentUser->getUsername() . " for roles {$roles}");
     if ($roles != '') {
         $loginRequired = true;
         $roles = explode(',', $roles);
         // If the user has any of the roles, let them in
         foreach ($roles as $role) {
             if ($currentUser->hasRole($role)) {
                 return $action;
             }
         }
     }
     // If we've got this far, then we should ask the DB if the current user has
     // access to the current module and controller
     // We're expecting user_access =>
     // user_role
     // OR array (controller => user_role)
     $userAccess = ifset($conf, 'user_access');
     if ($userAccess != null) {
         $loginRequired = true;
         // if it's a string, just get the access for the module
         $accessService = za()->getService('AccessService');
         // See if they have access to this module
         $access = $accessService->getAccessList($currentUser->getUsername(), $moduleName);
         if (count($access)) {
             // okay, they have access, so we're all cool
             return $action;
         }
     }
     if ($loginRequired) {
         $url = build_url($controllerName, $actionName, $action->getUserParams(), false, $moduleName);
         $_SESSION[NovemberController::RETURN_URL] = $url;
         // $action->setModuleName(ifset($this->config, 'login_module', 'default'));
         $action->setControllerName($this->config['login_controller']);
         $action->setActionName($this->config['login_action']);
     }
     return $action;
 }
Пример #14
0
 /**
  * Match the request.
  *
  * @param Zend_Controller_Request_Http $request The request object.
  * 
  * @return boolean
  */
 public function match(Zend_Controller_Request_Http $request)
 {
     if (!$this->_beforeModuleMatch()) {
         return false;
     }
     $this->fetchDefault();
     $front = $this->getFront();
     $path = trim($request->getPathInfo(), '/');
     $module = null;
     if ($path) {
         $parts = explode('/', $path);
     } else {
         $parts = explode('/', $this->_getDefaultPath());
     }
     // get module name
     if ($request->getModuleName()) {
         $module = $request->getModuleName();
     }
     if (!$module) {
         if (Mage::app()->getStore()->isAdmin()) {
             return false;
         }
     }
     // Does module match front name
     $loadByPath = false;
     if ($module != Mage::helper('link')->getFrontName()) {
         // If not, check the table for a match on the path
         if ($link = Mage::getModel('link/node')->loadByRequestPath($path)) {
             $module = Mage::helper('link')->getFrontName();
             $loadByPath = true;
         }
     }
     // Translate frontName to module
     $realModule = Mage::helper('link')->getModuleName();
     $request->setRouteName($this->getRouteByFrontName($module));
     // Get controller name
     $controller = $front->getDefault('controller');
     // Get action name
     $action = $front->getDefault('action');
     if ($loadByPath) {
         $request->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, ltrim(implode('/', $parts), '/'));
     } else {
         $request->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, ltrim(implode('/', array_slice($parts, 1)), '/'));
     }
     // Checking if this place should be secure
     $this->_checkShouldBeSecure($request, "/{$module}/{$controller}/{$action}");
     $controllerClassName = $this->_validateControllerClassName($realModule, $controller);
     if (!$controllerClassName) {
         return false;
     }
     // Instantiate controller class
     $controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $front->getResponse());
     if (!$controllerInstance->hasAction($action)) {
         return false;
     }
     // Set values
     $request->setModuleName($module);
     $request->setControllerName($controller);
     $request->setActionName($action);
     $request->setControllerModule($realModule);
     // Set parameters from pathinfo
     for ($i = 1, $length = sizeof($parts); $i < $length; $i += 2) {
         $request->setParam($parts[$i], isset($parts[$i + 1]) ? urldecode($parts[$i + 1]) : '');
     }
     // Dispatch action
     $request->setDispatched(true);
     $controllerInstance->dispatch($action);
     return true;
 }
Пример #15
0
 /**
  * Do basic validation for request to be cached
  *
  * @param Zend_Controller_Request_Http $request request
  *
  * @return bool
  */
 public function canProcessRequest(Zend_Controller_Request_Http $request)
 {
     $res = $this->isAllowed();
     $res = $res && $this->isEnabled();
     $fullActionName = $request->getModuleName() . '_' . $request->getControllerName() . '_' . $request->getActionName();
     if (!in_array($fullActionName, $this->_getAllowedActions())) {
         $res = false;
     }
     if ($request->getParam('no_cache')) {
         $res = false;
     }
     return $res;
 }
Пример #16
0
 /**
  * Match module front name
  *
  * @param Zend_Controller_Request_Http $request
  * @param string $param
  * @return string|null
  */
 protected function _matchModuleFrontName(Zend_Controller_Request_Http $request, $param)
 {
     // get module name
     if ($request->getModuleName()) {
         $moduleFrontName = $request->getModuleName();
     } else {
         if (!empty($param)) {
             $moduleFrontName = $param;
         } else {
             $moduleFrontName = $this->getFront()->getDefault('module');
             $request->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, '');
         }
     }
     if (!$moduleFrontName) {
         return null;
     }
     return $moduleFrontName;
 }
Пример #17
0
 /**
  * Get specific request processor based on request parameters.
  *
  * @param Zend_Controller_Request_Http $request
  * @return Enterprise_PageCache_Model_Processor_Default|false
  */
 public function getRequestProcessor(Zend_Controller_Request_Http $request)
 {
     if ($this->_requestProcessor === null) {
         $this->_requestProcessor = false;
         $configuration = Mage::getConfig()->getNode(self::XML_NODE_ALLOWED_CACHE);
         if ($configuration) {
             $configuration = $configuration->asArray();
         }
         $module = $request->getModuleName();
         $action = $request->getActionName();
         if (strtolower($action) == self::NOT_FOUND_ACTION && isset($configuration['_no_route'])) {
             $model = $configuration['_no_route'];
         } elseif (isset($configuration[$module])) {
             $model = $configuration[$module];
             $controller = $request->getControllerName();
             if (is_array($configuration[$module]) && isset($configuration[$module][$controller])) {
                 $model = $configuration[$module][$controller];
                 if (is_array($configuration[$module][$controller]) && isset($configuration[$module][$controller][$action])) {
                     $model = $configuration[$module][$controller][$action];
                 }
             }
         }
         if (isset($model) && is_string($model)) {
             $this->_requestProcessor = Mage::getModel($model);
         }
     }
     return $this->_requestProcessor;
 }
Пример #18
0
 public function match(Zend_Controller_Request_Http $request)
 {
     $this->fetchDefault();
     $front = $this->getFront();
     $p = explode('/', trim($request->getPathInfo(), '/'));
     // get module name
     if ($request->getModuleName()) {
         $module = $request->getModuleName();
     } else {
         $p = explode('/', trim($request->getPathInfo(), '/'));
         $module = !empty($p[0]) ? $p[0] : $this->getFront()->getDefault('module');
     }
     if (!$module) {
         return false;
     }
     $realModule = $this->getModuleByFrontName($module);
     if (!$realModule) {
         if ($moduleFrontName = array_search($module, $this->_modules)) {
             $realModule = $module;
             $module = $moduleFrontName;
         } else {
             return false;
         }
     }
     if (!Mage::app()->isInstalled()) {
         Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('install'))->sendResponse();
         exit;
     }
     if (Mage::app()->isInstalled() && !$request->isPost()) {
         $shouldBeSecure = substr(Mage::getStoreConfig('web/unsecure/base_url'), 0, 5) === 'https' || Mage::getStoreConfigFlag('web/secure/use_in_adminhtml') && substr(Mage::getStoreConfig('web/secure/base_url'), 0, 5) === 'https';
         if ($shouldBeSecure && !Mage::app()->getStore()->isCurrentlySecure()) {
             $url = Mage::getBaseUrl('link', true) . ltrim($request->getPathInfo(), '/');
             Mage::app()->getFrontController()->getResponse()->setRedirect($url)->sendResponse();
             exit;
         }
     }
     // get controller name
     if ($request->getControllerName()) {
         $controller = $request->getControllerName();
     } else {
         $controller = !empty($p[1]) ? $p[1] : $front->getDefault('controller');
     }
     $controllerFileName = $this->getControllerFileName($realModule, $controller);
     if (!$controllerFileName || !is_readable($controllerFileName)) {
         $controller = 'index';
         $action = 'noroute';
         $controllerFileName = $this->getControllerFileName($realModule, $controller);
     }
     $controllerClassName = $this->getControllerClassName($realModule, $controller);
     if (!$controllerClassName) {
         $controller = 'index';
         $action = 'noroute';
         $controllerFileName = $this->getControllerFileName($realModule, $controller);
     }
     // get action name
     if (empty($action)) {
         if ($request->getActionName()) {
             $action = $request->getActionName();
         } else {
             $action = !empty($p[2]) ? $p[2] : $front->getDefault('action');
         }
     }
     // include controller file if needed
     if (!class_exists($controllerClassName, false)) {
         include $controllerFileName;
         if (!class_exists($controllerClassName)) {
             throw Mage::exception('Mage_Core', Mage::helper('core')->__('Controller file was loaded but class does not exist'));
         }
     }
     // instantiate controller class
     $controllerInstance = new $controllerClassName($request, $front->getResponse());
     if (!$controllerInstance->hasAction($action)) {
         return false;
     }
     // set values only after all the checks are done
     $request->setModuleName($module);
     $request->setControllerName($controller);
     $request->setActionName($action);
     // set parameters from pathinfo
     for ($i = 3, $l = sizeof($p); $i < $l; $i += 2) {
         $request->setParam($p[$i], isset($p[$i + 1]) ? $p[$i + 1] : '');
     }
     // dispatch action
     $request->setDispatched(true);
     $controllerInstance->dispatch($action);
     return true;
     #$request->isDispatched();
 }
Пример #19
0
 /**
  * 根据Zend_Controller_Request_Http对象生成资源字符串
  * 
  * @param Zend_Controller_Request_Http $request
  * @return string
  */
 public static function parseHttpRequest(Zend_Controller_Request_Http $request)
 {
     return self::parsePageMvc($request->getActionName(), $request->getControllerName(), $request->getModuleName());
 }
Пример #20
0
 public function match(Zend_Controller_Request_Http $request)
 {
     $this->fetchDefault();
     $front = $this->getFront();
     $p = explode('/', trim($request->getPathInfo(), '/'));
     // get module name
     if ($request->getModuleName()) {
         $module = $request->getModuleName();
     } else {
         $module = !empty($p[0]) ? $p[0] : $this->getFront()->getDefault('module');
     }
     if (!$module) {
         if (Mage::app()->getStore()->isAdmin()) {
             $module = 'admin';
         } else {
             return false;
         }
     }
     $realModule = $this->getModuleByFrontName($module);
     if (!$realModule) {
         if ($moduleFrontName = array_search($module, $this->_modules)) {
             $realModule = $module;
             $module = $moduleFrontName;
         } else {
             return false;
         }
     }
     $request->setRouteName($this->getRouteByFrontName($module));
     if (!Mage::isInstalled()) {
         Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('install'))->sendResponse();
         exit;
     }
     $this->_checkShouldBeSecure($request);
     // get controller name
     if ($request->getControllerName()) {
         $controller = $request->getControllerName();
     } else {
         $controller = !empty($p[1]) ? $p[1] : $front->getDefault('controller');
     }
     $controllerFileName = $this->getControllerFileName($realModule, $controller);
     if (!$this->validateControllerFileName($controllerFileName)) {
         $controller = 'index';
         $action = 'noroute';
         $controllerFileName = $this->getControllerFileName($realModule, $controller);
     }
     $controllerClassName = $this->getControllerClassName($realModule, $controller);
     if (!$controllerClassName) {
         $controller = 'index';
         $action = 'noroute';
         $controllerFileName = $this->getControllerFileName($realModule, $controller);
     }
     // get action name
     if (empty($action)) {
         if ($request->getActionName()) {
             $action = $request->getActionName();
         } else {
             $action = !empty($p[2]) ? $p[2] : $front->getDefault('action');
         }
     }
     // include controller file if needed
     if (!class_exists($controllerClassName, false)) {
         if (!file_exists($controllerFileName)) {
             return false;
         }
         include $controllerFileName;
         if (!class_exists($controllerClassName, false)) {
             throw Mage::exception('Mage_Core', Mage::helper('core')->__('Controller file was loaded but class does not exist'));
         }
     }
     // instantiate controller class
     $controllerInstance = new $controllerClassName($request, $front->getResponse());
     if (!$controllerInstance->hasAction($action)) {
         return false;
     }
     // set values only after all the checks are done
     $request->setModuleName($module);
     $request->setControllerName($controller);
     $request->setActionName($action);
     // set parameters from pathinfo
     for ($i = 3, $l = sizeof($p); $i < $l; $i += 2) {
         $request->setParam($p[$i], isset($p[$i + 1]) ? $p[$i + 1] : '');
     }
     // dispatch action
     $request->setDispatched(true);
     $controllerInstance->dispatch($action);
     return true;
     #$request->isDispatched();
 }
Пример #21
0
 /**
  * {@inheritdoc}
  */
 public function getModuleName()
 {
     if (parent::getModuleName() === null) {
         return null;
     }
     return strtolower(trim(parent::getModuleName()));
 }
Пример #22
0
 /**
  * Match the request
  *
  * @param Zend_Controller_Request_Http $request
  * @return boolean
  */
 public function match(Zend_Controller_Request_Http $request)
 {
     //checking before even try to find out that current module
     //should use this router
     if (!$this->_beforeModuleMatch()) {
         return false;
     }
     $this->fetchDefault();
     $front = $this->getFront();
     $path = trim($request->getPathInfo(), '/');
     if ($path) {
         $p = explode('/', $path);
     } else {
         $p = explode('/', $this->_getDefaultPath());
     }
     // get module name
     if ($request->getModuleName()) {
         $module = $request->getModuleName();
     } else {
         if (!empty($p[0])) {
             $module = $p[0];
         } else {
             $module = $this->getFront()->getDefault('module');
             $request->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, '');
         }
     }
     if (!$module) {
         if (Mage::app()->getStore()->isAdmin()) {
             $module = 'admin';
         } else {
             return false;
         }
     }
     /**
      * Searching router args by module name from route using it as key
      */
     $modules = $this->getModuleByFrontName($module);
     if ($modules === false) {
         return false;
     }
     // checks after we found out that this router should be used for current module
     if (!$this->_afterModuleMatch()) {
         return false;
     }
     /**
      * Going through modules to find appropriate controller
      */
     $found = false;
     foreach ($modules as $realModule) {
         $request->setRouteName($this->getRouteByFrontName($module));
         // get controller name
         if ($request->getControllerName()) {
             $controller = $request->getControllerName();
         } else {
             if (!empty($p[1])) {
                 $controller = $p[1];
             } else {
                 $controller = $front->getDefault('controller');
                 $request->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, ltrim($request->getOriginalPathInfo(), '/'));
             }
         }
         // get action name
         if (empty($action)) {
             if ($request->getActionName()) {
                 $action = $request->getActionName();
             } else {
                 $action = !empty($p[2]) ? $p[2] : $front->getDefault('action');
             }
         }
         //checking if this place should be secure
         $this->_checkShouldBeSecure($request, '/' . $module . '/' . $controller . '/' . $action);
         $controllerClassName = $this->_validateControllerClassName($realModule, $controller);
         if (!$controllerClassName) {
             continue;
         }
         // instantiate controller class
         $controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $front->getResponse());
         if (!$controllerInstance->hasAction($action)) {
             continue;
         }
         $found = true;
         break;
     }
     /**
      * if we did not found any suitable
      */
     if (!$found) {
         if ($this->_noRouteShouldBeApplied()) {
             $controller = 'index';
             $action = 'noroute';
             $controllerClassName = $this->_validateControllerClassName($realModule, $controller);
             if (!$controllerClassName) {
                 return false;
             }
             // instantiate controller class
             $controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $front->getResponse());
             if (!$controllerInstance->hasAction($action)) {
                 return false;
             }
         } else {
             return false;
         }
     }
     // set values only after all the checks are done
     $request->setModuleName($module);
     $request->setControllerName($controller);
     $request->setActionName($action);
     $request->setControllerModule($realModule);
     // set parameters from pathinfo
     for ($i = 3, $l = sizeof($p); $i < $l; $i += 2) {
         $request->setParam($p[$i], isset($p[$i + 1]) ? urldecode($p[$i + 1]) : '');
     }
     // dispatch action
     $request->setDispatched(true);
     $controllerInstance->dispatch($action);
     return true;
 }
Пример #23
0
 /**
  * Initialize
  *
  * @access public
  * @return void
  */
 public function init()
 {
     $this->_request = $this->getRequest();
     $this->_module = $this->_request->getModuleName();
     $this->_controller = $this->_request->getControllerName();
     $this->_action = $this->_request->getActionName();
     $frontController = $this->getFrontController();
     $this->_plugins = $frontController->getPlugins();
     $this->_configs = $this->getInvokeArg('config');
     // Initialize view
     $this->_initView();
 }