public function match(Zend_Controller_Request_Http $request) { if (!Mage::app()->isInstalled()) { Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('install'))->sendResponse(); exit; } $pathInfo = trim($request->getPathInfo(), '/'); //echo $pathInfo;die(); $pathInfoAr = explode('/', $pathInfo); if ($pathInfoAr[0] == Mage::getStoreConfig('vc_miniblog/blog/router')) { if (isset($pathInfoAr[1])) { switch ($pathInfoAr[1]) { case 'tag': $request->setModuleName('vc_miniblog')->setControllerName('index')->setActionName('index'); $request->setParams(array('tag' => $pathInfoAr[2])); $request->setParams(array('tag' => $pathInfoAr[2])); break; case 'cat': $request->setModuleName('vc_miniblog')->setControllerName('index')->setActionName('index'); $request->setParams(array('cat' => $pathInfoAr[2])); break; default: $request->setModuleName('vc_miniblog')->setControllerName('index')->setActionName('postDetail'); $request->setParams(array('identifier' => $pathInfoAr[1])); break; } } else { $request->setModuleName('vc_miniblog')->setControllerName('index')->setActionName('index'); } return true; } return false; }
public function testSetGetParams() { $params = array('foo' => 'bar', 'boo' => 'bah', 'fee' => 'fi'); $this->_request->setParams($params); $received = $this->_request->getParams(); $this->assertSame($params, array_intersect_assoc($params, $received)); }
/** * @see XenForo_Route_Interface::match() * @param $routePath * @param \Zend_Controller_Request_Http $request * @param \XenForo_Router $router * @return \XenForo_RouteMatch */ public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router) { $customIndex = XenForo_Application::get('customIndex'); if ($customIndex->params) { $request->setParams($customIndex->params->toArray()); } return $router->getRouteMatch($customIndex->controllerClass, $routePath, $customIndex->majorSection, $customIndex->minorSection); }
function testSelected() { $vehicle = $this->createMMY('Honda', 'Civic', '2000'); $request = new Zend_Controller_Request_Http(); $request->setParams($vehicle->toTitleArray()); $search = new VF_Search(); $search->setRequest($request); $this->assertEquals($vehicle->getValue('model'), $search->getSelected('model')); }
public function testSetNullParamsUnsetsKeys() { $this->_request->setParams(array('foo' => 'bar', 'bar' => 'baz')); $this->assertEquals('bar', $this->_request->getParam('foo')); $this->assertEquals('baz', $this->_request->getParam('bar')); $this->_request->setParams(array('foo' => null)); $params = $this->_request->getParams(); $this->assertFalse(isset($params['foo'])); $this->assertTrue(isset($params['bar'])); }
public function testGetParamsWithGetAndPost() { $_GET = array('get' => true); $_POST = array('post' => true); $params = array('foo' => 'bar', 'boo' => 'bah', 'fee' => 'fi'); $this->_request->setParams($params); $expected = $params + $_GET + $_POST; $received = $this->_request->getParams(); $this->assertSame($params, array_intersect_assoc($params, $received)); }
/** * Verifica se tem permissão de acordo com os parâmetros na 'acl avançada' * @param array $params * @param bool $forceParams * @param bool $isAcl * @param bool $onlyUserParam * @param array $request * @return bool */ public function IsAllowed($params, $forceParams = true, $isAcl = true, $onlyUserParam = false, $request = []) { $this->_mdlParams = new Acl_Model_Params(); // Pegando a 'MCA' de acordo com o request ou com os dados passados $dbMca = Acl_Model_DbTable_Actions::getMcaByRequest($request); $controllerId = $dbMca->controller_id; if ($forceParams) { $controlParams = array(); $actions = $this->_mdlParams->getParamsByController($controllerId); foreach ($actions as $action) { $controlParams = array_merge($controlParams, $action['params']); } foreach ($params as $paramName => $paramValue) { $param_exists = false; foreach ($controlParams as $cparam) { $param_exists = $cparam['name'] == $paramName ? true : false; } if (!$param_exists) { // Criando o parâmetro no banco $this->_mdlParams->createParam(['acl_action_id' => $dbMca->action_id, 'name' => $paramName, 'description' => 'create by ' . __CLASS__]); } } } /* * Rota */ if ($isAcl) { $params['module'] = 'acl'; $params['controller'] = 'params'; $params['action'] = 'list'; $params['control'] = $controllerId; } else { $params['module'] = $dbMca->module_name; $params['controller'] = $dbMca->controller_name; $params['action'] = $dbMca->action_name; } $control = Zend_Controller_Front::getInstance()->getPlugin('Acl_Plugin_Control'); $control->setUserRole(Zend_Auth::getInstance()->getIdentity()->role_name); $access = $control->checkAccess($params['module'] . ':' . $params['controller'] . ':' . $params['action']); if ($onlyUserParam) { $request = new Zend_Controller_Request_Http(); $request->setParams($params); $access = $control->isParamAllowed($request); return $access; } else { if ($access) { $request = new Zend_Controller_Request_Http(); $request->setParams($params); $access = $control->isParamAllowed($request); } } return $access; }
function testYearSelected_YearEnd() { $civic2000 = $this->createMMY('Honda', 'Civic', '2000'); $civic2001 = $this->createMMY('Honda', 'Civic', '2001'); $request = new Zend_Controller_Request_Http(); $request->setParams(array('make' => $civic2000->getValue('make'), 'model' => $civic2000->getValue('model'), 'year_start' => $civic2000->getLevel('year')->getId(), 'year_end' => $civic2001->getLevel('year')->getId())); $search = new VF_Search(); $search->setRequest($request); $searchlevel = new VF_SearchLevel_TestSub2(); $searchlevel->display($search, 'year', null, null, 'year_end'); $this->assertFalse($searchlevel->getSelected($civic2000->getLevel('year'))); $this->assertTrue($searchlevel->getSelected($civic2001->getLevel('year'))); }
/** * Rewritten function of the standard controller. Tries to match the pathinfo on url parameters. * * @see Mage_Core_Controller_Varien_Router_Standard::match() * * @param Zend_Controller_Request_Http $request The http request object that needs to be mapped on Action * Controllers. */ public function match(Zend_Controller_Request_Http $request) { if (!Mage::isInstalled()) { Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('install'))->sendResponse(); exit; } $identifier = trim($request->getPathInfo(), '/'); //URL Search after habbeda $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; //$identifier = trim($request->getPathInfo(), '/'); if (strpos($url, "/alle/") <= 0 && strpos($url, "/all/") <= 0) { return false; } // if successfully gained url parameters, use them and dispatch ActionController action $request->setRouteName('landingpagesaa')->setModuleName('landingpagesaa')->setControllerName('index')->setActionName('index'); //->setParam('test', "test"); $urlpara = explode("/filter/", $url); if (!empty($urlpara[1])) { $urlparas = explode("?", $urlpara[1]); // Parse url params $params = explode('/', trim($urlparas[0], '/')); $layerParams = array(); $total = count($params); for ($i = 0; $i < $total - 1; $i++) { if (isset($params[$i + 1])) { $layerParams[$params[$i]] = urldecode($params[$i + 1]); ++$i; } } // Add post params to parsed ones from url // Usefull to easily override params $layerParams += $request->getPost(); // Add params to request $request->setParams($layerParams); // Save params in registry - used later to generate links Mage::register('layer_params', $layerParams); } $request->setRequestUri($url); $request->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, $identifier); return true; }
public function match(Zend_Controller_Request_Http $request) { if (!Mage::app()->isInstalled()) { Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('install'))->sendResponse(); exit; } $pathInfo = trim($request->getPathInfo(), '/'); //echo $pathInfo;die(); $pathInfoAr = explode('/', $pathInfo); //if ($pathInfoAr[0] == Mage::getStoreConfig('vc_shopbybrands/general/router')) { if ($pathInfoAr[0] == Mage::getStoreConfig('vc_shopbybrands/general/router')) { if (isset($pathInfoAr[1])) { $request->setModuleName('vc_shopbybrands')->setControllerName('brands')->setActionName('view'); $request->setParams(array('identifier' => str_replace('.html', '', $pathInfoAr[1]))); } else { $request->setModuleName('vc_shopbybrands')->setControllerName('brands')->setActionName('index'); } return true; } return false; }
/** * Returns information about how to reroute if a page not found error occurs. * * @param string Controller name * @param string Action * * @return array Reroute array */ protected function _rerouteNotFound($controllerName, $action) { $this->_request->setParams(array('_controllerName' => $controllerName, '_action' => $action)); list($controllerName, $action) = $this->_dependencies->getNotFoundErrorRoute(); return array('controllerName' => $controllerName, 'action' => $action); }
function testSelected() { $this->switchSchema('make,model,year'); $vehicle = $this->createMMY('Honda', 'Civic', '2000'); $request = new Zend_Controller_Request_Http(); $request->setParams($vehicle->toTitleArray()); $search = new VF_Search_Form(); VF_Singleton::getInstance()->setRequest($request); $this->assertEquals($vehicle->getValue('model'), $search->getSelected('model')); }
/** * Allows the dispatching and processing of a separate * controller request from inside an existing view. * * Should be used for read only stuff (please!) * * @param string $controller * @param string $action * @param array $params A list of parameters to bind into the new request * @param string $module * @param array $requestParams A list of parameters to pull from the current request */ public function Dispatch($controller, $action, $params = array(), $module = null, $requestParams = array()) { // If no module, use the current request module $oldRequest = null; $ctrl = Zend_Controller_Front::getInstance(); $oldRequest = $ctrl->getRequest(); if ($module == null) { /* @var $request Zend_Controller_Request_Abstract */ $name = null; if ($oldRequest) { $name = $oldRequest->getModuleName(); } if ($name && $name != 'default') { $module = $name; } } else { if ($module == 'default') { $module = ''; } } $key = $controller . '|' . $action . '|' . $module; if (isset(self::$__DISPATCHED[$key])) { za()->log("Recursive dispatch detected {$key} ", Zend_Log::ERR); return; } self::$__DISPATCHED[$key] = true; $request = new Zend_Controller_Request_Http(); $response = new Zend_Controller_Response_Http(); $request->setControllerName($controller); $request->setActionName($action); if ($params) { $request->setParams($params); } if (count($requestParams)) { foreach ($requestParams as $rp) { // get from the current request and stick into the new $value = $oldRequest->getParam($rp, ''); $request->setParam($rp, $value); } } if ($module) { $request->setModuleName($module); } $oldView = Zend_Registry::get(NovemberApplication::$ZEND_VIEW); $allPaths = $oldView->getAllPaths(); $newView = new CompositeView(); foreach ($allPaths['script'] as $scriptPath) { $newView->addScriptPath($scriptPath); } foreach ($allPaths['helper'] as $prefix => $path) { $newView->addHelperPath($path, $prefix); } foreach ($allPaths['filter'] as $prefix => $path) { $newView->addFilterPath($path, $prefix); } Zend_Registry::set(NovemberApplication::$ZEND_VIEW, $newView); $dispatcher = new InjectingDispatcher(); $dispatcher->addControllerDirectory('controllers', 'default'); $dispatcher->setParams($params)->setResponse($response); $request->setDispatched(true); $dispatcher->dispatch($request, $response); $response->outputBody(); Zend_Registry::set(NovemberApplication::$ZEND_VIEW, $oldView); }