Register autoload scope
This process allow include scope file which can contain classes
definition which are used for this scope
public static registerScope ( string $code ) | ||
$code | string | scope code |
/** * Checks cache for cached pages. If found the original response is served, * otherwise normal processing will occur. * * Observes: controller_action_predispatch * * @param $observer * @return void */ public function checkAndServeCachedPage(Varien_Event_Observer $observer) { /** * @var $controllerAction Mage_Core_Controller_Varien_Action * @var $engine Brim_PageCache_Model_Engine */ /* * controller_action_predispatch occurs before the autoloader sets the scope for the compiler. When the compiler * is enabled there is the possibility of creating a redeclare class fatal error if we need any class that is * included in the compilers current scope file. ESP. an issue with the checkout scope. Registering the scope * here prevents the fatal error from occurring. */ if (defined('COMPILER_INCLUDE_PATH')) { $controllerAction = $observer->getControllerAction(); Varien_Autoload::registerScope($controllerAction->getRequest()->getRouteName()); } $engine = Mage::getSingleton('brim_pagecache/engine'); if (!$engine->isEnabled()) { return; } $engine->servePage($this); }
/** * Dispatch event before action * * @return void */ public function preDispatch() { if (!$this->getFlag('', self::FLAG_NO_CHECK_INSTALLATION)) { if (!Mage::isInstalled()) { $this->setFlag('', self::FLAG_NO_DISPATCH, true); $this->_redirect('install'); return; } } // Prohibit disabled store actions if (Mage::isInstalled() && !Mage::app()->getStore()->getIsActive()) { Mage::app()->throwStoreException(); } if ($this->_rewrite()) { return; } if (!$this->getFlag('', self::FLAG_NO_START_SESSION)) { $checkCookie = in_array($this->getRequest()->getActionName(), $this->_cookieCheckActions) && !$this->getRequest()->getParam('nocookie', false); $cookies = Mage::getSingleton('core/cookie')->get(); /** @var $session Mage_Core_Model_Session */ $session = Mage::getSingleton('core/session', array('name' => $this->_sessionNamespace))->start(); if (empty($cookies)) { if ($session->getCookieShouldBeReceived()) { $this->setFlag('', self::FLAG_NO_COOKIES_REDIRECT, true); $session->unsCookieShouldBeReceived(); $session->setSkipSessionIdFlag(true); } elseif ($checkCookie) { if (isset($_GET[$session->getSessionIdQueryParam()]) && Mage::app()->getUseSessionInUrl() && $this->_sessionNamespace != Mage_Adminhtml_Controller_Action::SESSION_NAMESPACE) { $session->setCookieShouldBeReceived(true); } else { $this->setFlag('', self::FLAG_NO_COOKIES_REDIRECT, true); } } } } Mage::app()->loadArea($this->getLayout()->getArea()); if ($this->getFlag('', self::FLAG_NO_COOKIES_REDIRECT) && Mage::getStoreConfig('web/browser_capabilities/cookies')) { $this->_forward('noCookies', 'index', 'core'); return; } if ($this->getFlag('', self::FLAG_NO_PRE_DISPATCH)) { return; } Varien_Autoload::registerScope($this->getRequest()->getRouteName()); Mage::dispatchEvent('controller_action_predispatch', array('controller_action' => $this)); Mage::dispatchEvent('controller_action_predispatch_' . $this->getRequest()->getRouteName(), array('controller_action' => $this)); Mage::dispatchEvent('controller_action_predispatch_' . $this->getFullActionName(), array('controller_action' => $this)); }
/** * Dispatches event before action */ public function preDispatch() { if (!$this->getFlag('', self::FLAG_NO_CHECK_INSTALLATION)) { if (!Mage::isInstalled()) { $this->setFlag('', self::FLAG_NO_DISPATCH, true); $this->_redirect('install'); return; } } // Prohibit disabled store actions if (Mage::isInstalled() && !Mage::app()->getStore()->getIsActive()) { Mage::app()->throwStoreException(); } if ($this->_rewrite()) { return; } if (!$this->getFlag('', self::FLAG_NO_START_SESSION)) { $checkCookie = in_array($this->getRequest()->getActionName(), $this->_cookieCheckActions); $checkCookie = $checkCookie && !$this->getRequest()->getParam('nocookie', false); $cookies = Mage::getSingleton('core/cookie')->get(); if ($checkCookie && empty($cookies)) { $this->setFlag('', self::FLAG_NO_COOKIES_REDIRECT, true); } Mage::getSingleton('core/session', array('name' => $this->_sessionNamespace))->start(); } Mage::app()->loadArea($this->getLayout()->getArea()); if ($this->getFlag('', self::FLAG_NO_COOKIES_REDIRECT) && Mage::getStoreConfig('web/browser_capabilities/cookies')) { $this->_forward('noCookies', 'index', 'core'); return; } if ($this->getFlag('', self::FLAG_NO_PRE_DISPATCH)) { return; } Mage::dispatchEvent('controller_action_predispatch', array('controller_action' => $this)); Mage::dispatchEvent('controller_action_predispatch_' . $this->getRequest()->getRouteName(), array('controller_action' => $this)); Varien_Autoload::registerScope($this->getRequest()->getRouteName()); Mage::dispatchEvent('controller_action_predispatch_' . $this->getFullActionName(), array('controller_action' => $this)); }
public function match(Zend_Controller_Request_Http $request) { if (Mage::app()->getStore()->isAdmin()) { return false; } $pageId = $request->getPathInfo(); // remove suffix if any $suffix = Mage::getStoreConfig('catalog/seo/category_url_suffix'); if ($suffix && '/' != $suffix) { $pageId = str_replace($suffix, '', $pageId); } //add trailing slash $pageId = trim($pageId, '/') . '/'; $reservedKey = Mage::getStoreConfig('amshopby/seo/key') . '/'; //check if we have reserved word in the url if (false === strpos($pageId, '/' . $reservedKey)) { if (substr($pageId, 0, strlen($reservedKey)) != $reservedKey) { return false; } } else { $reservedKey = '/' . $reservedKey; } // get layered navigation params as string list($cat, $params) = explode($reservedKey, $pageId, 2); $params = trim($params, '/'); if ($params) { $params = explode('/', $params); } // remember for futire use in the helper if ($params) { Mage::register('amshopby_current_params', $params); } $cat = trim($cat, '/'); if ($cat) { // normal category // if somebody has old urls in the cache. if (!Mage::getStoreConfig('amshopby/seo/urls')) { return false; } Varien_Autoload::registerScope('catalog'); $cat = $cat . $suffix; $urlRewrite = Mage::getModel('core/url_rewrite')->setStoreId(Mage::app()->getStore()->getId())->loadByRequestPath($cat); if (!$urlRewrite->getId()) { $store = $request->getParam('___from_store'); $store = Mage::app()->getStore($store)->getId(); if (!$store) { return false; } $urlRewrite = Mage::getModel('core/url_rewrite')->setStoreId($store)->loadByRequestPath($cat); } if (!$urlRewrite->getId()) { return false; } $request->setPathInfo($cat); $request->setModuleName('catalog'); $request->setControllerName('category'); $request->setActionName('view'); $request->setParam('id', $urlRewrite->getCategoryId()); $urlRewrite->rewrite($request); } else { // root category $realModule = 'Amasty_Shopby'; $request->setPathInfo(trim($reservedKey, '/')); $request->setModuleName('amshopby'); $request->setRouteName('amshopby'); $request->setControllerName('index'); $request->setActionName('index'); $request->setControllerModule($realModule); $file = Mage::getModuleDir('controllers', $realModule) . DS . 'IndexController.php'; include $file; //compatibility with 1.3 $class = $realModule . '_IndexController'; $controllerInstance = new $class($request, $this->getFront()->getResponse()); $request->setDispatched(true); $controllerInstance->dispatch('index'); } return true; }
/** * Implements database-centered URL rewrite logic (translates human friendly URLs into standard * module/controller/action/params form). * * @see Mage_Core_Model_Url_Rewrite::rewrite() * * This method is based on Mage_Core_Model_Url_Rewrite::rewrite() source. Modifications are marked with comments. */ public function rewrite(Zend_Controller_Request_Http $request = null, Zend_Controller_Response_Http $response = null) { /* @var $_core Mana_Core_Helper_Data */ $_core = Mage::helper(strtolower('Mana_Core')); $conditionalWord = $_core->getStoreConfig('mana_filters/seo/conditional_word'); $categorySuffix = Mage::helper('manapro_filterseolinks')->getCategoryUrlSuffix(); if (!Mage::isInstalled()) { return false; } if (is_null($request)) { $request = Mage::app()->getFrontController()->getRequest(); } if (is_null($response)) { $response = Mage::app()->getFrontController()->getResponse(); } if (is_null($this->getStoreId()) || false === $this->getStoreId()) { $this->setStoreId(Mage::app()->getStore()->getId()); } /** * We have two cases of incoming paths - with and without slashes at the end ("/somepath/" and "/somepath"). * Each of them matches two url rewrite request paths - with and without slashes at the end ("/somepath/" and "/somepath"). * Choose any matched rewrite, but in priority order that depends on same presence of slash and query params. */ $requestCases = array(); $pathInfo = urldecode($request->getPathInfo()); $origSlash = substr($pathInfo, -1) == '/' ? '/' : ''; $requestPath = trim($pathInfo, '/'); if ($conditionalWord && ($conditionPos = strpos($requestPath, $conditionalWord . '/')) === 0) { Varien_Autoload::registerScope('catalog'); Varien_Autoload::registerScope('cms'); $pageId = Mage::getStoreConfig(Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE); $this->_setPageCategoryId($pageId); $parameters = substr($requestPath, $conditionPos + strlen($conditionalWord . '/')); $_SERVER['QUERY_STRING'] = http_build_query($this->_getQueryParameters($parameters), '', '&'); $request->setAlias(self::REWRITE_REQUEST_PATH_ALIAS, $this->getRequestPath()); if (Mage::getStoreConfig('web/url/use_store') && ($storeCode = Mage::app()->getStore()->getCode())) { $targetUrl = $request->getBaseUrl() . '/' . $storeCode; } else { $targetUrl = $request->getBaseUrl(); } if ($queryString = $this->_getQueryString()) { if (strrpos($targetUrl, '/') !== strlen($targetUrl) - 1) { $targetUrl .= '/'; } $targetUrl .= '?' . $queryString; } if ($parameters) { $request->setRequestUri($request->getBaseUrl() . str_replace('/' . $conditionalWord . '/' . $parameters, '', $request->getRequestString())); $request->setPathInfo(); } $request->setRequestUri($targetUrl); $request->setPathInfo(''); return true; } elseif ($conditionalWord && ($conditionPos = strpos($requestPath, '/' . $conditionalWord . '/')) != false) { Varien_Autoload::registerScope('catalog'); Varien_Autoload::registerScope('cms'); $cmsPath = substr($requestPath, 0, $conditionPos); $page = Mage::getModel('cms/page'); $pageId = $page->checkIdentifier($cmsPath, Mage::app()->getStore()->getId()); if ($pageId) { $this->_setPageCategoryId($pageId); $parameters = substr($requestPath, $conditionPos + strlen('/' . $conditionalWord . '/')); $_SERVER['QUERY_STRING'] = http_build_query($this->_getQueryParameters($parameters), '', '&'); $request->setAlias(self::REWRITE_REQUEST_PATH_ALIAS, $this->getRequestPath()); if (Mage::getStoreConfig('web/url/use_store') && ($storeCode = Mage::app()->getStore()->getCode())) { $targetUrl = $request->getBaseUrl() . '/' . $storeCode . '/' . $cmsPath; } else { $targetUrl = $request->getBaseUrl() . '/' . $cmsPath; } if ($queryString = $this->_getQueryString()) { $targetUrl .= '?' . $queryString; } if ($parameters) { $request->setRequestUri($request->getBaseUrl() . str_replace('/' . $conditionalWord . '/' . $parameters, '', $request->getRequestString())); $request->setPathInfo(); } $request->setRequestUri($targetUrl); $request->setPathInfo($cmsPath); return true; } } $altSlash = $origSlash ? '' : '/'; // If there were final slash - add nothing to less priority paths. And vice versa. $queryString = $this->_getQueryString(); // Query params in request, matching "path + query" has more priority if ($queryString) { $requestCases[] = $requestPath . $origSlash . '?' . $queryString; $requestCases[] = $requestPath . $altSlash . '?' . $queryString; } $requestCases[] = $requestPath . $origSlash; $requestCases[] = $requestPath . $altSlash; // MANA BEGIN: in case we have specially named segment in URL suspect it is layered navigation url. Then // add additional checks to $requestCases if ($conditionalWord && ($conditionPos = strpos($requestPath, '/' . $conditionalWord . '/')) != false && (!$categorySuffix || $categorySuffix == '/' || strrpos($requestPath, $categorySuffix) == strlen($requestPath) - strlen($categorySuffix))) { Varien_Autoload::registerScope('catalog'); $layeredPath = substr($requestPath, 0, $conditionPos) . ($categorySuffix != '/' ? $categorySuffix : ''); $requestCases[] = $layeredPath . $origSlash; $requestCases[] = $layeredPath . $altSlash; } else { $layeredPath = false; } // MANA END $this->loadByRequestPath($requestCases); /** * Try to find rewrite by request path at first, if no luck - try to find by id_path */ if (!$this->getId() && isset($_GET['___from_store'])) { try { $fromStoreId = Mage::app()->getStore($_GET['___from_store'])->getId(); } catch (Exception $e) { return false; } $this->setStoreId($fromStoreId)->loadByRequestPath($requestCases); if (!$this->getId()) { return false; } $this->setStoreId(Mage::app()->getStore()->getId())->loadByIdPath($this->getIdPath()); } if (!$this->getId()) { return false; } // MANA BEGIN: in case we found rewrite based on filtered navigation url, do some magic passes // around request object and $_SERVER['QUERY_STRING'] to make it look like // "apparel/shoes.html?shoe_type=52&shoe_type-show-all=1" $parameters = ''; if ($layeredPath !== false && in_array($this->getRequestPath(), array($layeredPath . $origSlash, $layeredPath . $altSlash)) && $this->getCategoryId()) { if ($categorySuffix && $categorySuffix != '/') { $parameters = substr($requestPath, $conditionPos + strlen('/' . $conditionalWord . '/'), strlen($requestPath) - strlen($categorySuffix) - $conditionPos - strlen('/' . $conditionalWord . '/')); } else { $parameters = substr($requestPath, $conditionPos + strlen('/' . $conditionalWord . '/')); } $_SERVER['QUERY_STRING'] = http_build_query($this->_getQueryParameters($parameters), '', '&'); } // MANA END $request->setAlias(self::REWRITE_REQUEST_PATH_ALIAS, $this->getRequestPath()); $external = substr($this->getTargetPath(), 0, 6); $isPermanentRedirectOption = $this->hasOption('RP'); if ($external === 'http:/' || $external === 'https:') { if ($isPermanentRedirectOption) { header('HTTP/1.1 301 Moved Permanently'); } header("Location: " . $this->getTargetPath()); exit; } else { $targetUrl = $request->getBaseUrl() . '/' . $this->getTargetPath(); } $isRedirectOption = $this->hasOption('R'); if ($isRedirectOption || $isPermanentRedirectOption) { if (Mage::getStoreConfig('web/url/use_store') && ($storeCode = Mage::app()->getStore()->getCode())) { $targetUrl = $request->getBaseUrl() . '/' . $storeCode . '/' . $this->getTargetPath(); } if ($isPermanentRedirectOption) { header('HTTP/1.1 301 Moved Permanently'); } header('Location: ' . $targetUrl); exit; } if (Mage::getStoreConfig('web/url/use_store') && ($storeCode = Mage::app()->getStore()->getCode())) { $targetUrl = $request->getBaseUrl() . '/' . $storeCode . '/' . $this->getTargetPath(); } $queryString = $this->_getQueryString(); if ($queryString) { $targetUrl .= '?' . $queryString; } if ($parameters) { $request->setRequestUri($request->getBaseUrl() . str_replace('/' . $conditionalWord . '/' . $parameters, '', $request->getRequestString())); $request->setPathInfo(); } $request->setRequestUri($targetUrl); $request->setPathInfo($this->getTargetPath()); $request->setActionName(''); return true; }