match() public method

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.
public match ( array $url, array $context = [] ) : string | false
$url array An array of parameters to check matching with.
$context array An array of the current request context. Contains information such as the current host, scheme, port, base directory and other url params.
return string | false Either a string URL for the parameters if they match or false.
コード例 #1
0
ファイル: SlugRoute.php プロジェクト: Xety/Xeta
 /**
  * Slug the prefix, controller and plugin params before passing them on to the
  * parent class
  *
  * @param array $url Array of parameters to convert to a string.
  * @param array $context An array of the current request context.
  *   Contains information such as the current host, scheme, port, and base
  *   directory.
  *
  * @return false|string Either false or a string URL.
  */
 public function match(array $url, array $context = [])
 {
     $url = $this->_slugerize($url);
     if (!$this->_slugedDefaults) {
         $this->_slugedDefaults = true;
         $this->defaults = $this->_slugerize($this->defaults);
     }
     return parent::match($url, $context);
 }
コード例 #2
0
ファイル: InflectedRoute.php プロジェクト: nrother/cakephp
 /**
  * Underscores the prefix, controller and plugin params before passing them on to the
  * parent class
  *
  * @param array $url Array of parameters to convert to a string.
  * @param array $context An array of the current request context.
  *   Contains information such as the current host, scheme, port, and base
  *   directory.
  * @return string|false Either a string URL for the parameters if they match or false.
  */
 public function match(array $url, array $context = [])
 {
     $url = $this->_underscore($url);
     if (!$this->_inflectedDefaults) {
         $this->_inflectedDefaults = true;
         $this->defaults = $this->_underscore($this->defaults);
     }
     return parent::match($url, $context);
 }
コード例 #3
0
ファイル: AjaxDashedRoute.php プロジェクト: m-esprit/web-app
 /**
  * match method
  *
  * @param array $url
  * @param array $context
  * @return boolean|string
  */
 public function match(array $url, array $context = [])
 {
     if (preg_match("/^ajax.+/", $url['action']) == 0) {
         return false;
     }
     $url['action'] = preg_replace("/^ajax(.+)/", '$1', $url['action']);
     $url = $this->_dasherize($url);
     return parent::match($url, $context);
 }
コード例 #4
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.
  * @param array $context An array of the current request context.
  *   Contains information such as the current host, scheme, port, and base
  *   directory.
  * @return mixed either false or a string URL.
  */
 public function match(array $url, array $context = array())
 {
     if (isset($url['controller']) && isset($url['plugin']) && $url['plugin'] !== $url['controller']) {
         return false;
     }
     $this->defaults['controller'] = $url['controller'];
     $result = parent::match($url, $context);
     unset($this->defaults['controller']);
     return $result;
 }
コード例 #5
0
ファイル: EntityRoute.php プロジェクト: esaul314/norn-cms
 public function match(array $url, array $context = [])
 {
     //debug($url); debug($context); die;
     if (isset($url['_entity'])) {
         $entity = $url['_entity'];
         preg_match_all('@:(\\w+)@', $this->template, $matches);
         foreach ($matches[1] as $field) {
             $url[$field] = $entity[$field];
         }
         $url = ['slug' => $url['_entity']['slug'], 'controller' => $url['_entity']['controller'], 'action' => $url['_entity']['action'], 'plugin' => $url['_entity']['plugin']];
     }
     return parent::match($url, $context);
 }
コード例 #6
0
 /**
  * Testing that patterns on the :action param work properly.
  *
  * @return void
  */
 public function testPatternOnAction()
 {
     $route = new Route('/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' => []);
     $this->assertEquals($expected, $result);
     $result = $route->parse('/blog/foobar');
     $this->assertFalse($result);
 }
コード例 #7
0
 /**
  * Test match() with trailing ** style routes.
  *
  * @return void
  */
 public function testMatchTrailing()
 {
     $route = new Route('/pages/**', ['controller' => 'pages', 'action' => 'display']);
     $id = 'test/ spaces/漢字/la†în';
     $result = $route->match(['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);
 }
コード例 #8
0
ファイル: RouteTest.php プロジェクト: ripzappa0924/carte0.0.1
 /**
  * Test matching of parameters where one parameter name starts with another parameter name
  *
  * @return void
  */
 public function testMatchSimilarParameters()
 {
     $route = new Route('/:thisParam/:thisParamIsLonger');
     $url = array('thisParamIsLonger' => 'bar', 'thisParam' => 'foo');
     $result = $route->match($url);
     $expected = '/foo/bar';
     $this->assertEquals($expected, $result);
 }