Пример #1
0
 /**
  * Attempt to match a url array.  If the url matches the route parameters + settings, then
  * return a generated string url.  If the url doesn't match the route parameters false will be returned.
  * This method handles the reverse routing or conversion of url arrays into string urls.
  *
  * @param array $url An array of parameters to check matching with.
  * @return mixed Either a string url for the parameters if they match or false.
  */
 public function match($url)
 {
     if (empty($url['lang'])) {
         $url['lang'] = Configure::read('Config.language');
     }
     return parent::match($url);
 }
Пример #2
0
/**
 * Reverse route plugin shortcut URLs. If the plugin and controller
 * are not the same the match is an auto fail.
 *
 * @param array $url Array of parameters to convert to a string.
 * @return mixed either false or a string URL.
 */
	public function match($url) {
		if (isset($url['controller']) && isset($url['plugin']) && $url['plugin'] != $url['controller']) {
			return false;
		}
		$this->defaults['controller'] = $url['controller'];
		$result = parent::match($url);
		unset($this->defaults['controller']);
		return $result;
	}
Пример #3
0
 public function match($params)
 {
     $subdomain = isset($params['subdomain']) ? $params['subdomain'] : '';
     unset($params['subdomain']);
     $path = parent::match($params);
     $domain = $this->_getDomain();
     if ($subdomain) {
         $path = 'http://' . $subdomain . '.' . $domain . $path;
     }
     return $path;
 }
 public function match($params)
 {
     print_r($params);
     $subdomain = isset($params['subdomain']) ? $params['subdomain'] : 'w3';
     unset($params['subdomain']);
     $path = parent::match($params);
     if ($subdomain) {
         $path = 'http://' . $subdomain . '.localhost' . $path;
     }
     return $path;
 }
 /**
  * Skips pattern checking if invoked with Router::url(array(..., 'skipPatterns' => true));
  *
  * @param array $url
  * @return mixed|void
  */
 public function match($url)
 {
     if ($this->skipPatterns) {
         $originalOptions = $this->options;
         $this->options = array();
         $res = parent::match($url);
         $this->options = $originalOptions;
         return $res;
     } else {
         return parent::match($url);
     }
 }
Пример #6
0
 /**
  * Checks if an URL array matches this route instance
  *
  * @param array $url An array of parameters to check matching with.
  * @return mixed Either a string URL for the parameters if they match or false.
  * @see CakeRoute::match()
  */
 public function match($url)
 {
     if (isset($url['prefix']) && isset($url['action'])) {
         $prefix = $url['prefix'];
         $url['prefix'] = str_replace('_', '.', $url['prefix']);
         $url['action'] = str_replace($prefix . '_', '', $url['action']);
     }
     $match = parent::match($url);
     if ($match && isset($url['action']) && $url['action'] == 'index') {
         $match = str_replace('/index', '', $match);
     }
     return $match;
 }
Пример #7
0
 /**
  * Attempt to match a url array.  If the url matches the route parameters + settings, then
  * return a generated string url.  If the url doesn't match the route parameters false will be returned.
  * This method handles the reverse routing or conversion of url arrays into string urls.
  *
  * @param array $url An array of parameters to check matching with.
  * @return mixed Either a string url for the parameters if they match or false.
  */
 public function match($url)
 {
     if (empty($url['lang'])) {
         $url['lang'] = $this->getDefaultLanguage();
     }
     $parentMatch = parent::match($url);
     if (!$parentMatch) {
         return false;
     }
     if ($this->_shouldStripDefaultLanguageOnMatch()) {
         $parentMatch = preg_replace('#/' . DEFAULT_LANGUAGE . '/#', '/', $parentMatch);
     }
     return $parentMatch;
 }
 /**
  * Attempt to match a url array. If the url matches the route parameters and
  * settings, then return a generated string url. If the url doesn't match
  * the route parameters, false will be returned. This method handles the
  * reverse routing or conversion of url arrays into string urls.
  *
  * @param array $url An array of parameters to check matching with.
  * @return mixed Either a string url for the parameters if they match or false.
  */
 public function match($url)
 {
     // Looking for a route with routeName
     if (!empty($url['routeName'])) {
         // $this Route has no routeName and we are looking for one -> no match
         if (empty($this->options['routeName'])) {
             return false;
         }
         // $this Route has a different routeName than the one we are looking for -> no match
         if ($url['routeName'] !== $this->options['routeName']) {
             return false;
         }
         // Having reached here, the routeName matches, so we overwrite $url values
         // with the ones from the matched route ($this). This way we ensure it
         // finally matches when we pass it to parent::match()
         foreach ($this->defaults as $key => $value) {
             $url[$key] = $value;
         }
         unset($url['routeName']);
     }
     return parent::match($url);
 }
Пример #9
0
 /**
  * Test that match can handle array named parameters
  *
  * @return void
  */
 public function testMatchNamedParametersArray()
 {
     $route = new CakeRoute('/:controller/:action/*');
     $url = array('controller' => 'posts', 'action' => 'index', 'filter' => array('one', 'model' => 'value'));
     $result = $route->match($url);
     $expected = '/posts/index/filter%5B0%5D:one/filter%5Bmodel%5D:value';
     $this->assertEquals($expected, $result);
     $url = array('controller' => 'posts', 'action' => 'index', 'filter' => array('one', 'model' => array('two', 'order' => 'field')));
     $result = $route->match($url);
     $expected = '/posts/index/filter%5B0%5D:one/filter%5Bmodel%5D%5B0%5D:two/filter%5Bmodel%5D%5Border%5D:field';
     $this->assertEquals($expected, $result);
 }
Пример #10
0
 /**
  * Testing that patterns on the :action param work properly.
  *
  * @return void
  */
 public function testPatternOnAction()
 {
     $route = new CakeRoute('/blog/:action/*', array('controller' => 'blog_posts'), array('action' => 'other|actions'));
     $result = $route->match(array('controller' => 'blog_posts', 'action' => 'foo'));
     $this->assertFalse($result);
     $result = $route->match(array('controller' => 'blog_posts', 'action' => 'actions'));
     $this->assertEquals('/blog/actions/', $result);
     $result = $route->parse('/blog/other');
     $expected = array('controller' => 'blog_posts', 'action' => 'other', 'pass' => array(), 'named' => array());
     $this->assertEquals($expected, $result);
     $result = $route->parse('/blog/foobar');
     $this->assertFalse($result);
 }
Пример #11
0
 function match($url)
 {
     if (isset($url['admin']) && $url['admin'] === true) {
         if (isset($url['plugin']) && strtolower($url['plugin']) == 'admin') {
             unset($url['plugin']);
             unset($url['admin']);
             $controller = isset($url['controller']) ? $url['controller'] . '/' : '';
             $action = isset($url['action']) ? $url['action'] . '/' : '';
             unset($url['controller']);
             unset($url['action']);
             return '/admin/' . $controller . $action . implode('/', array_values($url));
         }
     }
     if (isset($url['default'])) {
         if ($url['default']) {
             return '/';
         }
         unset($url['default']);
     }
     if (!empty($url['slug'])) {
         return $url['slug'];
     }
     return parent::match($url);
 }
 /**
  * Test match() with trailing ** style routes.
  *
  * @return void
  */
 public function testMatchTrailing()
 {
     $route = new CakeRoute('/pages/**', array('controller' => 'pages', 'action' => 'display'));
     $id = 'test/ spaces/漢字/la†în';
     $result = $route->match(array('controller' => 'pages', 'action' => 'display', $id));
     $expected = '/pages/test/%20spaces/%E6%BC%A2%E5%AD%97/la%E2%80%A0%C3%AEn';
     $this->assertEquals($expected, $result);
 }
Пример #13
0
 /**
  * test match() with greedy routes, named parameters and passed args.
  *
  * @return void
  */
 function testMatchWithNamedParametersAndPassedArgs()
 {
     Router::connectNamed(true);
     $route = new CakeRoute('/:controller/:action/*', array('plugin' => null));
     $result = $route->match(array('controller' => 'posts', 'action' => 'index', 'plugin' => null, 'page' => 1));
     $this->assertEqual($result, '/posts/index/page:1');
     $result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null, 5));
     $this->assertEqual($result, '/posts/view/5');
     $result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null, 5, 'page' => 1, 'limit' => 20, 'order' => 'title'));
     $this->assertEqual($result, '/posts/view/5/page:1/limit:20/order:title');
     $route =& new CakeRoute('/test2/*', array('controller' => 'pages', 'action' => 'display', 2));
     $result = $route->match(array('controller' => 'pages', 'action' => 'display', 1));
     $this->assertFalse($result);
     $result = $route->match(array('controller' => 'pages', 'action' => 'display', 2, 'something'));
     $this->assertEqual($result, '/test2/something');
     $result = $route->match(array('controller' => 'pages', 'action' => 'display', 5, 'something'));
     $this->assertFalse($result);
 }
Пример #14
0
 /**
  * Test matching of parameters where one parameter name starts with another parameter name
  *
  * @return void
  */
 public function testMatchSimilarParameters()
 {
     $route = new CakeRoute('/:thisParam/:thisParamIsLonger');
     $url = array('thisParamIsLonger' => 'bar', 'thisParam' => 'foo');
     $result = $route->match($url);
     $expected = '/foo/bar';
     $this->assertEquals($expected, $result);
 }
Пример #15
0
 /**
  * Matches the model's id and converts it to a slug
  *
  * @param array $url Cake url array
  * @return boolean
  */
 public function match($url)
 {
     if (isset($this->options['models'])) {
         foreach ($this->options['models'] as $checkNamed => $slugField) {
             if (is_numeric($checkNamed)) {
                 $checkNamed = $slugField;
                 $slugField = null;
             }
             if (isset($url[$checkNamed])) {
                 $slugSet = $this->getSlugs($checkNamed, $slugField);
                 if (empty($slugSet)) {
                     continue;
                 }
                 if (isset($slugSet[$url[$checkNamed]])) {
                     $url[] = $slugSet[$url[$checkNamed]];
                     unset($url[$checkNamed]);
                 }
             }
         }
     }
     return parent::match($url);
 }
Пример #16
0
 /**
  * Matches the model's id and converts it to a slug
  *
  * @param array $url Cake url array
  * @return boolean
  */
 public function match($url)
 {
     foreach ($this->models as $modelName => $options) {
         list($paramType, $paramName) = $this->params($options);
         $slugSet = $this->getSlugs($modelName);
         if (empty($slugSet)) {
             continue;
         }
         switch ($paramType) {
             case 'pass':
                 if (isset($url[$paramName]) && isset($slugSet[$url[$paramName]])) {
                     $url[$paramName] = $slugSet[$url[$paramName]];
                 }
                 break;
             case 'named':
                 if (isset($url[$paramName]) && isset($slugSet[$url[$paramName]])) {
                     $url[] = $slugSet[$url[$paramName]];
                     unset($url[$paramName]);
                 }
                 break;
         }
     }
     return parent::match($url);
 }
Пример #17
0
 /**
  * Reverse route page shortcut urls. Treats all existing page routes as normal
  * Can optionally validate a page path using the 'validate' key
  *
  * @param array $url Array of parameters to convert to a string.
  * @return mixed either false or a string url.
  */
 public function match($url)
 {
     if (!isset($url['controller']) || !isset($url['action'])) {
         return false;
     }
     if ($url['controller'] != $this->options['controller'] || $url['action'] != $this->options['action']) {
         return false;
     }
     if (isset($url[0]) && !isset($url['page'])) {
         $url['page'] = $url[0];
     }
     if (!isset($url['page'])) {
         return false;
     }
     if (isset($url['validate']) && $url['validate'] == true) {
         $path = trim(str_replace('//', '', (string) $url['page']), '/');
         if (!file_exists(APP . 'View' . DS . $this->options['controller'] . DS . $path . '.ctp')) {
             return false;
         }
     }
     unset($url[0], $url['prefix'], $url['plugin'], $url['validate']);
     return parent::match($url);
 }
Пример #18
0
 public function match($url)
 {
     return parent::match($url);
 }
Пример #19
0
 /**
  * Having greedNamed enabled should not capture routing.prefixes.
  *
  * @return void
  */
 public function testMatchGreedyNamedExcludesPrefixes()
 {
     Configure::write('Routing.prefixes', array('admin'));
     Router::reload();
     $route = new CakeRoute('/sales/*', array('controller' => 'sales', 'action' => 'index'));
     $this->assertFalse($route->match(array('controller' => 'sales', 'action' => 'index', 'admin' => 1)), 'Greedy named consume routing prefixes.');
 }