public function testAddParam() { $this->markTestSkipped("Check if is request test"); $this->object->explode("/index/index"); $this->object->addParams(array("hello" => "ciao")); $this->object->addParams(array("bella" => 'zi')); $p = $this->object->getParams(); $this->assertEquals(2, count($p)); $this->assertEquals("ciao", $p["hello"]); $this->assertEquals("zi", $p["bella"]); }
/** * @dataProvider getSetProvider * @covers Route::getController * @covers Route::setController * @covers Route::getAction * @covers Route::setAction * @covers Route::getParams * @covers Route::setParams * * @param string $controller * @param string $action * @param array $params */ public function testGetSet($controller, $action, array $params) { $route = new Route('a', 'b', array('c')); $route->setController($controller); $this->assertEquals($controller, $route->getController()); $route->setAction($action); $this->assertEquals($action, $route->getAction()); $route->setParams($params); $this->assertEquals($params, $route->getParams()); }
<?php // get the absolute path to system $sys_path = dirname(__FILE__); // set the include path set_include_path($sys_path . PATH_SEPARATOR . get_include_path()); // include some required components require_once 'components/common.php'; require_once 'components/autoload.php'; // get config instance $config = get_config(); // store the system path in config $config->set('path.system', $sys_path); // get route library $route = new Route(); // get controller, action and request params $controller = $route->getController(); $action = $route->getAction(); $params = $route->getParams(); // store in config $config->set('request.controller', $controller); $config->set('request.action', $action); $config->set('request.params', $params); // init the application $application = new Application($controller, $action); // EOF
public function getParam($name, $default = null) { return $this->matchedRoute->getParams()->get($name, $default); }
/** * @param Route $route Route object matching rules */ protected function setGetData($route) { $routePath = str_replace(array('(', ')'), array('', ''), $route->getPath()); $trim = explode('<', $routePath); $parsed_url = str_replace(array($this->basePath), array(''), $this->url); $parsed_url = preg_replace("#{$trim['0']}#", '', $parsed_url, 1); // sets the parameters passed in the URL foreach ($route->getParams() as $key => $param) { preg_match("#{$param}#", $parsed_url, $results); if (isset($results[0])) { $_GET[$key] = $results[0]; $parsed_url = str_replace($results[0], '', $parsed_url); } } // if no parameter in the URL, it sets the default values from the table foreach ($route->getDefaults() as $key => $default) { if (!isset($_GET[$key])) { $_GET[$key] = $default; } } }