public function setUp()
    {
        $savePath = ini_get('session.save_path');
        if (strpos($savePath, ';')) {
            $savePath = explode(';', $savePath);
            $savePath = array_pop($savePath);
        }
        if (empty($savePath)) {
            $this->markTestSkipped('Cannot test FlashMessenger due to unavailable session save path');
        }

        if (headers_sent()) {
            $this->markTestSkipped('Cannot test FlashMessenger: cannot start session because headers already sent');
        }
        Zend_Session::start();

        $this->front      = Zend_Controller_Front::getInstance();
        $this->front->resetInstance();
        $this->front->setControllerDirectory(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . '_files');
        $this->front->returnResponse(true);
        $this->request    = new Zend_Controller_Request_Http();
        $this->request->setControllerName('helper-flash-messenger');
        $this->response   = new Zend_Controller_Response_Cli();
        $this->controller = new HelperFlashMessengerController($this->request, $this->response, array());
        $this->helper     = new Zend_Controller_Action_Helper_FlashMessenger($this->controller);
    }
예제 #2
0
 public function testSetGetControllerName()
 {
     $this->_request->setControllerName('foo');
     $this->assertEquals('foo', $this->_request->getControllerName());
     $this->_request->setControllerName('bar');
     $this->assertEquals('bar', $this->_request->getControllerName());
 }
 /**
  * @param Zend_Controller_Request_Http $request
  */
 public function preDispatch($request)
 {
     // dont filter anything if a resident is logged in
     $session = new Zend_Session_Namespace();
     if ($session->currentResidentId) {
         $session->currentResident = Table_Residents::getInstance()->find($session->currentResidentId)->current();
         return;
     }
     // allow index and session controller to all
     if ($request->getControllerName() == 'index' || $request->getControllerName() == 'session') {
         return;
     }
     // Authenticate direct requests for non-html stuff
     if ($request->getParam('format') !== "html") {
         // The requestor provided a username
         if (isset($_SERVER['PHP_AUTH_USER'])) {
             $resident = Table_Residents::getInstance()->findResidentByEmailAndPasswordhash($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
             if ($resident) {
                 $session->currentResidentId = $resident->getId();
                 $session->currentResident = $resident;
                 return;
             }
         }
         header('WWW-Authenticate: Basic realm="WG-Organizer"');
         header('HTTP/1.0 401 Unauthorized');
         die;
     }
     // else redirect to frontpage
     $request->setControllerName('index');
     $request->setActionName('index');
 }
예제 #4
0
 /**
  * Test Function for replaceAction
  *
  * @return void
  */
 public function replaceAction()
 {
     $request = new Zend_Controller_Request_Http();
     $request->setControllerName('index')->setActionName('reset')->setDispatched(false);
     $response = new Zend_Controller_Response_Http();
     $front = Zend_Controller_Front::getInstance();
     $front->setRequest($request)->setResponse($response);
 }
 public function testCorrectViewHelperPathShouldBePropagatedWhenSubControllerInvokedInDefaultModule()
 {
     require_once $this->basePath . '/_files/modules/default/controllers/Admin/HelperController.php';
     $this->request->setControllerName('admin_helper')->setActionName('render');
     $controller = new Admin_HelperController($this->request, $this->response, array());
     $this->helper->render();
     $body = $this->response->getBody();
     $this->assertContains('SampleZfHelper invoked', $body, 'Received ' . $body);
 }
예제 #6
0
파일: AclTest.php 프로젝트: kandy/system
 /**
  */
 public function testPreDispatch()
 {
     $this->acl->addRole('guest');
     $request = new Zend_Controller_Request_Http();
     $request->setModuleName('1');
     $request->setControllerName('2');
     $request->setActionName('3');
     $this->object->preDispatch($request);
     self::assertEquals('default', $request->getModuleName());
     self::assertEquals('error', $request->getControllerName());
     self::assertEquals('denied', $request->getActionName());
 }
예제 #7
0
 /**
  * @param Zend_Controller_Request_Http $request
  */
 public function preDispatch($request)
 {
     if ($request->getControllerName() == 'setup' || $request->getControllerName() == 'error') {
         // allow all setup actions
         // and all error actions
         return;
     } else {
         // redirect other to setup install
         $request->setControllerName('setup');
         $request->setActionName('install');
     }
 }
예제 #8
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;
     }
     $front = $this->getFront();
     $path = trim($request->getPathInfo(), '/');
     $p = explode('/', $path);
     if (count($p) == 0 || !$this->_pluarizeName($p[0])) {
         return false;
     } else {
         $module = $this->_pluarizeName($p[0]);
         $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;
         }
         // set values only after all the checks are done
         $request->setModuleName($module);
         $request->setControllerName('index');
         $action = $this->_getActionFromPathInfo($p);
         $request->setActionName($action);
         $realModule = 'Zefir_Dealers';
         $request->setControllerModule($realModule);
         $request->setRouteName('dealers');
         // dispatch action
         $request->setDispatched(true);
         /**
          * Set params for the request
          */
         if ($action == 'view') {
             $request->setParam('dealer_code', $p[1]);
         } else {
             // 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]) : '');
             }
         }
         // instantiate controller class and dispatch action
         $controllerClassName = $this->_validateControllerClassName($realModule, 'index');
         $controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $front->getResponse());
         $controllerInstance->dispatch($action);
         return true;
     }
 }
예제 #9
0
 /**
  * Validate and Match Cms Page and modify request
  *
  * @param Zend_Controller_Request_Http $request
  * @return bool
  */
 public function match(Zend_Controller_Request_Http $request)
 {
     if (Mage::app()->getStore()->isAdmin()) {
         return false;
     }
     $sellerAtttributeName = Mage::getConfig()->getNode('default/seller_page/attribute_name');
     $seoDisplay = Mage::getConfig()->getNode('default/seller_page/seo_display');
     if (empty($sellerAtttributeName)) {
         //Seller attribute not configured
         return false;
     }
     $pageId = $request->getPathInfo();
     $param = explode('/', $pageId);
     $seller = '';
     if (count($param) > 1 and strtolower($param[1]) == $seoDisplay and !empty($param[2])) {
         //Identify Seller
         $sellerPage = $param[2];
         if (strpos($sellerPage, '.') !== false) {
             $sellerPage = urldecode(substr($sellerPage, 0, -5));
             if ($sellerPage) {
                 $seller = str_replace('-', ' ', $sellerPage);
             } else {
                 return false;
             }
         } else {
             $seller = $sellerPage;
         }
     } else {
         return false;
     }
     if ($seller) {
         Mage::register('seller_company', $seller);
         $realModule = 'Cybage_Marketplace';
         $request->setModuleName('marketplace');
         $request->setRouteName('marketplace');
         $request->setControllerName('seller');
         $request->setActionName('sellerinfo');
         $request->setControllerModule($realModule);
         $request->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, ltrim($request->getRequestString(), '/'));
         $file = Mage::getModuleDir('controllers', $realModule) . DS . 'SellerController.php';
         include $file;
         //compatibility with 1.3
         $class = $realModule . '_SellerController';
         $controllerInstance = new $class($request, $this->getFront()->getResponse());
         $request->setDispatched(true);
         $controllerInstance->dispatch('sellerinfo');
     }
     return true;
 }
예제 #10
0
파일: Router.php 프로젝트: victorkho/telor
 protected function forwardShopby()
 {
     $reservedKey = Mage::getStoreConfig('amshopby/seo/key');
     $realModule = 'Amasty_Shopby';
     $this->request->setPathInfo($reservedKey);
     $this->request->setModuleName('amshopby');
     $this->request->setRouteName('amshopby');
     $this->request->setControllerName('index');
     $this->request->setActionName('index');
     $this->request->setControllerModule($realModule);
     $file = Mage::getModuleDir('controllers', $realModule) . DS . 'IndexController.php';
     include $file;
     //compatibility with 1.3
     $class = $realModule . '_IndexController';
     $controllerInstance = new $class($this->request, $this->getFront()->getResponse());
     $this->request->setDispatched(true);
     $controllerInstance->dispatch('index');
 }
예제 #11
0
 public function testAuthorization()
 {
     $app = za();
     za()->setUser(new GuestUser());
     $pluginConf = $app->getConfig('plugins');
     $conf = array('default' => array('user' => array('edit' => 'User,Admin', 'list' => 'Admin')), 'login_controller' => 'testcontroller', 'login_action' => 'testaction');
     $plugin = new AuthorizationPlugin($conf);
     $action = new Zend_Controller_Request_Http();
     $action->setControllerName("user");
     $action->setActionName('edit');
     $action->setModuleName('default');
     $plugin->preDispatch($action);
     // Make sure it's redirected to the user / login controller
     $this->assertEqual($action->getControllerName(), 'testcontroller');
     $this->assertEqual($action->getActionName(), 'testaction');
     // Now test that a user with role User is fine
     $user = new User();
     za()->setUser($user);
     $user->role = 'User';
     $action->setControllerName("user");
     $action->setActionName('edit');
     $plugin->preDispatch($action);
     $this->assertEqual($action->getControllerName(), 'user');
     $this->assertEqual($action->getActionName(), 'edit');
     // Make sure they can't LIST
     $action->setControllerName('user');
     $action->setActionName('list');
     $plugin->preDispatch($action);
     $this->assertEqual($action->getControllerName(), 'testcontroller');
     $this->assertEqual($action->getActionName(), 'testaction');
     // Now make them an admin, make sure they can do both the above
     $user->role = 'Admin';
     $action->setControllerName("user");
     $action->setActionName('edit');
     $plugin->preDispatch($action);
     $this->assertEqual($action->getControllerName(), 'user');
     $this->assertEqual($action->getActionName(), 'edit');
     // Make sure they can't LIST
     $action->setControllerName('user');
     $action->setActionName('list');
     $plugin->preDispatch($action);
     $this->assertEqual($action->getControllerName(), 'user');
     $this->assertEqual($action->getActionName(), 'list');
 }
예제 #12
0
 /**
  * @param Zend_Controller_Request_Http $request
  */
 public function preDispatch($request)
 {
     // dont filter anything if a resident is logged in
     $session = new Zend_Session_Namespace();
     // Sets the resident id so the next if loads the user ;)
     if ($request->getParam('appauth_key')) {
         $session->currentResidentId = Table_Residents::getInstance()->findByAppAuthKey($request->getParam('appauth_key'));
     }
     if ($session->currentResidentId) {
         $session->currentResident = Table_Residents::getInstance()->find($session->currentResidentId)->current();
         return;
     }
     // allow index and session controller to all
     if ($request->getControllerName() == 'index' || $request->getControllerName() == 'session') {
         return;
     }
     // else redirect to frontpage
     $request->setControllerName('index');
     $request->setActionName('index');
 }
예제 #13
0
 /**
  * Test valid action on valid controller; test pre/postDispatch
  */
 public function testDispatch4()
 {
     $request = new Zend_Controller_Request_Http();
     $request->setControllerName('foo');
     $request->setActionName('bar');
     $response = new Zend_Controller_Response_Cli();
     $this->_dispatcher->dispatch($request, $response);
     $body = $this->_dispatcher->getResponse()->getBody();
     $this->assertContains('Bar action called', $body);
     $this->assertContains('preDispatch called', $body);
     $this->assertContains('postDispatch called', $body);
 }
예제 #14
0
 /**
  * Validate and Match shop view and modify request
  */
 public function match(Zend_Controller_Request_Http $request)
 {
     $front = $this->getFront();
     if (!Mage::isInstalled()) {
         Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('install'))->sendResponse();
         exit;
     }
     $routerConfig = Mage::getStoreConfig('shopbybrand/general/router');
     $_end = Mage::getStoreConfig(Magestore_Shopbybrand_Helper_Data::XML_FRONTEND_LINK);
     $_path = urldecode(trim($request->getPathInfo(), '/'));
     if (strpos($_path, $_end)) {
         $_link_params = explode('/', str_replace($_end, '/', $_path), -1);
     } else {
         $_link_params = explode('/', $_path . '/', -1);
     }
     $_count_params = count($_link_params);
     $found = false;
     if (isset($_link_params[0])) {
         $router = $_link_params[0];
         if ($router == $routerConfig) {
             $request->setRouteName('shopbybrand')->setControllerModule('Magestore_Shopbybrand')->setModuleName('brand');
             $module = 'shopbybrand';
             if (isset($_link_params[1]) && $_link_params[1]) {
                 $request->setControllerName($_link_params[1]);
             }
             if (isset($_link_params[2]) && $_link_params[2]) {
                 $request->setActionName($_link_params[2]);
             }
             // get controller name
             if ($request->getControllerName()) {
                 $controller = $request->getControllerName();
             } else {
                 if (!empty($_link_params[1])) {
                     $controller = $_link_params[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($_link_params[2]) ? $_link_params[2] : $front->getDefault('action');
                 }
             }
             //checking if this place should be secure
             $this->_checkShouldBeSecure($request, '/' . $module . '/' . $controller . '/' . $action);
             $controllerClassName = $this->_validateControllerClassName('Magestore_Shopbybrand', $controller);
             if (!$controllerClassName) {
                 return false;
             }
             $controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $front->getResponse());
             if (!$controllerInstance->hasAction($action)) {
                 return false;
             }
             $found = true;
         }
     }
     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;
         }
     } else {
         return true;
     }
 }
예제 #15
0
 */
use Pimcore\Model\Object;
use Pimcore\Model\Document;
// determines if we're in Pimcore\Console mode
$pimcoreConsole = defined('PIMCORE_CONSOLE') && true === PIMCORE_CONSOLE;
$workingDirectory = getcwd();
chdir(__DIR__);
include_once "../config/startup.php";
chdir($workingDirectory);
// CLI \Zend_Controller_Front Setup, this is required to make it possible to make use of all rendering features
// this includes $this->action() in templates, ...
$front = \Zend_Controller_Front::getInstance();
Pimcore::initControllerFront($front);
$request = new \Zend_Controller_Request_Http();
$request->setModuleName(PIMCORE_FRONTEND_MODULE);
$request->setControllerName("default");
$request->setActionName("default");
$front->setRequest($request);
$front->setResponse(new \Zend_Controller_Response_Cli());
// generic pimcore setup
\Pimcore::setSystemRequirements();
\Pimcore::initAutoloader();
\Pimcore::initConfiguration();
\Pimcore::setupFramework();
\Pimcore::initLogger();
\Pimcore::initModules();
\Pimcore::initPlugins();
//Activate Inheritance for cli-scripts
\Pimcore::unsetAdminMode();
Document::setHideUnpublished(true);
Object\AbstractObject::setHideUnpublished(true);
예제 #16
0
 protected function _dispatchFrontController()
 {
     try {
         try {
             Zend_Controller_Front::getInstance()->dispatch()->sendResponse();
         } catch (WebVista_App_AuthException $wae) {
             try {
                 $loginRequest = new Zend_Controller_Request_Http();
                 $loginRequest->setControllerName('login')->setActionName('index');
                 Zend_Controller_Front::getInstance()->getRouter()->removeDefaultRoutes();
                 Zend_Controller_Front::getInstance()->getRouter()->addRoute('default', new Zend_Controller_Router_Route('login/:index'));
                 Zend_Controller_Front::getInstance()->setRequest($loginRequest)->dispatch()->sendResponse();
             } catch (WebVista_App_AuthException $wae2) {
                 //do nothing, we are directing to login controller so this exception is expected
             }
         }
     } catch (Exception $e) {
         Zend_Controller_Front::getInstance()->getResponse()->setRawHeader('HTTP/1.1 500 Server Error');
         echo $e->getMessage();
     }
     return $this;
 }
예제 #17
0
 public function testGetViewScript()
 {
     $request = new Zend_Controller_Request_Http();
     $request->setControllerName('view')->setActionName('test');
     $response = new Zend_Controller_Response_Cli();
     Zend_Controller_Front::getInstance()->setControllerDirectory(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files');
     require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'ViewController.php';
     $controller = new ViewController($request, $response);
     $script = $controller->getViewScript();
     $this->assertContains('view' . DIRECTORY_SEPARATOR . 'test.phtml', $script);
     $script = $controller->getViewScript('foo');
     $this->assertContains('view' . DIRECTORY_SEPARATOR . 'foo.phtml', $script);
 }
예제 #18
0
 public function testRenderUsingViewRenderer()
 {
     Zend_Controller_Action_HelperBroker::addHelper(new Zend_Controller_Action_Helper_ViewRenderer());
     $request = new Zend_Controller_Request_Http();
     $request->setControllerName('view')->setActionName('script');
     $response = new Zend_Controller_Response_Cli();
     Zend_Controller_Front::getInstance()->setControllerDirectory(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files');
     require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'ViewController.php';
     $controller = new ViewController($request, $response);
     $controller->scriptAction();
     $this->assertContains('Inside custom/renderScript.php', $response->getBody());
 }
예제 #19
0
 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;
 }
 /**
  * create scheduler task
  * 
  * @return Tinebase_Scheduler_Task
  */
 protected function _createTask()
 {
     $request = new Zend_Controller_Request_Http();
     $request->setControllerName('Tinebase_Alarm');
     $request->setActionName('sendPendingAlarms');
     $request->setParam('eventName', 'Tinebase_Event_Async_Minutely');
     $task = new Tinebase_Scheduler_Task();
     $task->setMonths("Jan-Dec");
     $task->setWeekdays("Sun-Sat");
     $task->setDays("1-31");
     $task->setHours("0-23");
     $task->setMinutes("0/1");
     $task->setRequest($request);
     return $task;
 }
예제 #21
0
 /**
  * @see ZF-2693
  */
 public function testForcingCamelCasedActionsNotRequestedWithWordSeparatorsShouldRaiseNotices()
 {
     $this->_dispatcher->setParam('useCaseSensitiveActions', true);
     $request = new Zend_Controller_Request_Http();
     $request->setModuleName('admin');
     $request->setControllerName('foo-bar');
     $request->setActionName('bazBat');
     $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
     $response = new Zend_Controller_Response_Cli();
     set_error_handler(array($this, 'handleErrors'));
     try {
         $this->_dispatcher->dispatch($request, $response);
         $body = $this->_dispatcher->getResponse()->getBody();
         restore_error_handler();
         $this->assertTrue(isset($this->error));
         $this->assertContains('deprecated', $this->error);
     } catch (Zend_Controller_Exception $e) {
         restore_error_handler();
         $this->fail('camelCased actions should succeed when forced');
     }
 }
 /**
  * Adds a request.
  *
  * For the first parameter, users can pass in either the name of the 
  * controller or a request object.
  *
  * @param  string|Zend_Controller_Request_Abstract $controller Controller name or request object
  * @param  string $action Action name
  * @param  array $parameters Request parameters
  * @return Zend_Scheduler_Task This instance
  */
 public function addRequest($controller, $action = 'index', array $parameters = array())
 {
     if ($controller instanceof Zend_Controller_Request_Abstract) {
         $request = $controller;
     } else {
         $request = new Zend_Controller_Request_Http();
         $request->setControllerName($controller)->setActionName($action)->setParams($parameters);
     }
     $this->_requests[] = $request;
     return $this;
 }
예제 #23
0
 /**
  * Test that extra arguments get passed
  */
 public function testDispatch5()
 {
     $request = new Zend_Controller_Request_Http();
     $request->setControllerName('index');
     $request->setActionName('args');
     $this->_controller->setResponse(new Zend_Controller_Response_Cli());
     $this->_controller->addParam('foo');
     $this->_controller->addParam('bar');
     $response = $this->_controller->dispatch($request);
     $body = $response->getBody();
     $this->assertContains('foo; bar', $body);
 }
예제 #24
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();
 }
예제 #25
0
 public function testDisableOutputBuffering()
 {
     if (!defined('TESTS_ZEND_CONTROLLER_DISPATCHER_OB') || !TESTS_ZEND_CONTROLLER_DISPATCHER_OB) {
         $this->markTestSkipped('Skipping output buffer disabling in Zend_Controller_Dispatcher_Standard');
     }
     $request = new Zend_Controller_Request_Http();
     $request->setControllerName('ob');
     $request->setActionName('index');
     $this->_dispatcher->setParam('disableOutputBuffering', true);
     $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
     $response = new Zend_Controller_Response_Cli();
     $this->_dispatcher->dispatch($request, $response);
     $body = $this->_dispatcher->getResponse()->getBody();
     $this->assertEquals('', $body, $body);
 }
예제 #26
0
 public function testNamespacedControllerWithCamelCaseAction()
 {
     $this->_dispatcher->setControllerDirectory(array(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files'));
     $request = new Zend_Controller_Request_Http();
     $request->setModuleName('admin');
     $request->setControllerName('foo-bar');
     $request->setActionName('baz.bat');
     $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
     $response = new Zend_Controller_Response_Cli();
     $this->_dispatcher->dispatch($request, $response);
     $body = $this->_dispatcher->getResponse()->getBody();
     $this->assertContains("Admin_FooBar::bazBat action called", $body, $body);
 }
예제 #27
0
 public function testModuleSubdirControllerFound()
 {
     Zend_Controller_Front::getInstance()->addControllerDirectory(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'controllers', 'foo');
     $request = new Zend_Controller_Request_Http();
     $request->setModuleName('foo');
     $request->setControllerName('admin_index');
     $request->setActionName('index');
     $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
     $response = new Zend_Controller_Response_Cli();
     $this->_dispatcher->dispatch($request, $response);
     $body = $this->_dispatcher->getResponse()->getBody();
     $this->assertContains("Foo_Admin_IndexController::indexAction() called", $body, $body);
 }
예제 #28
0
 public function testSanelyDiscardOutputBufferOnException()
 {
     $request = new Zend_Controller_Request_Http();
     $request->setControllerName('ob');
     $request->setActionName('exception');
     $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
     $response = new Zend_Controller_Response_Cli();
     try {
         $this->_dispatcher->dispatch($request, $response);
         $this->fail('Exception should have been rethrown');
     } catch (Exception $e) {
     }
     $body = $this->_dispatcher->getResponse()->getBody();
     $this->assertNotContains("In exception action", $body, $body);
     $this->assertNotContains("Foo", $body, $body);
 }
 public function match(Zend_Controller_Request_Http $request)
 {
     if (Mage::app()->getStore()->isAdmin()) {
         return false;
     }
     $pageId = $request->getPathInfo();
     // remove suffix if any
     $suffix = Mage::helper('amshopby/url')->getUrlSuffix();
     if ($suffix && '/' != $suffix) {
         $pageId = str_replace($suffix, '', $pageId);
     }
     //add trailing slash
     $pageId = trim($pageId, '/') . '/';
     $reservedKey = Mage::getStoreConfig('amshopby/seo/key') . '/';
     //  canon/
     //  electronics - false
     //  electronics/shopby/canon/
     //  electronics/shopby/red/
     //  electronics/shopby/
     //  shopby/
     //  shopby/red/
     //  shopby/canon/ - false
     //  shopby/manufacturer-canon/ - false
     //  manufacturer-canon/ - true
     // starts from shopby
     $isAllProductsPage = substr($pageId, 0, strlen($reservedKey)) == $reservedKey;
     // has shopby in the middle
     $isCategoryPage = false !== strpos($pageId, '/' . $reservedKey);
     if (!Mage::getStoreConfig('amshopby/seo/urls')) {
         // If path info have something after reserved key
         if (($isAllProductsPage || $isCategoryPage) && substr($pageId, -strlen($reservedKey), strlen($reservedKey)) != $reservedKey) {
             return false;
         }
     }
     if ($isAllProductsPage) {
         // no support for old style urls
         if ($this->hasBrandIn(self::MIDDLE, $pageId)) {
             return false;
         }
     }
     if (!$isAllProductsPage && !$isCategoryPage) {
         if (!$this->hasBrandIn(self::BEGINNING, $pageId)) {
             return false;
         }
         //it is brand page and we modify the url to be in the old style
         $pageId = $reservedKey . $pageId;
     }
     // 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;
         }
         // we do not use Mage::getVersion() here as it is not defined in the old versions.
         $isVersionEE13 = 'true' == (string) Mage::getConfig()->getNode('modules/Enterprise_UrlRewrite/active');
         if ($isVersionEE13) {
             $urlRewrite = Mage::getModel('enterprise_urlrewrite/url_rewrite');
             /* @var $urlRewrite Enterprise_UrlRewrite_Model_Url_Rewrite */
             if (version_compare(Mage::getVersion(), '1.13.0.2', '>=')) {
                 $catReqPath = array('request' => $cat . $suffix, 'whole' => $cat);
             } else {
                 $catReqPath = array($cat);
             }
             $urlRewrite->setStoreId(Mage::app()->getStore()->getId())->loadByRequestPath($catReqPath);
         } else {
             $urlRewrite = Mage::getModel('core/url_rewrite');
             /* @var $urlRewrite Mage_Core_Model_Url_Rewrite */
             $cat = $cat . $suffix;
             $catReqPath = $cat;
             $urlRewrite->setStoreId(Mage::app()->getStore()->getId())->loadByRequestPath($catReqPath);
         }
         // todo check in ee13
         if (!$urlRewrite->getId()) {
             $store = $request->getParam('___from_store');
             $store = Mage::app()->getStore($store)->getId();
             if (!$store) {
                 return false;
             }
             $urlRewrite->setData(array())->setStoreId($store)->loadByRequestPath($catReqPath);
             if (!$urlRewrite->getId()) {
                 return false;
             }
         }
         $request->setPathInfo($cat);
         $request->setModuleName('catalog');
         $request->setControllerName('category');
         $request->setActionName('view');
         if ($isVersionEE13) {
             $categoryId = str_replace('catalog/category/view/id/', '', $urlRewrite->getTargetPath());
             $request->setParam('id', $categoryId);
         } else {
             $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;
 }
예제 #30
0
 /**
  * Test that classes are found in modules, using a prefix
  */
 public function testNamespacedModules()
 {
     $this->_dispatcher->setControllerDirectory(array('default' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files', 'admin' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files/Admin'));
     $request = new Zend_Controller_Request_Http();
     $request->setControllerName('foo');
     $request->setActionName('bar');
     $request->setParam('module', 'admin');
     $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
     $this->assertEquals(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files/Admin', $this->_dispatcher->getDispatchDirectory());
     $response = new Zend_Controller_Response_Cli();
     $this->_dispatcher->dispatch($request, $response);
     $body = $this->_dispatcher->getResponse()->getBody();
     $this->assertContains("Admin_Foo::bar action called", $body, $body);
 }