/** * Returns true if the URL matches this route, false otherwise. * * @param string $url The URL * @param array $context The context * * @return array An array of parameters */ public function matchesUrl($url, $context = array()) { if (false === ($parameters = parent::matchesUrl($url, $context))) { return false; } // enforce the sf_method requirement if (in_array(strtolower($context['method']), $this->requirements['sf_method'])) { return $parameters; } return false; }
/** * @see sfRoute * @param string $url The URL * @param array $context The context * @return array An array of parameters */ public function matchesUrl($url, $context = array()) { $parameters = parent::matchesUrl($url, $context); $matches = array(); if (preg_match('/^([^(]+)(\\(.*\\))(\\..*?)$/', $parameters['file_name'], $matches)) { $parameters['file_name'] = $matches[1] . $matches[3]; preg_match_all('/\\((.*?):(.*?)\\)/', $matches[2], $matches); $parameters = array_merge($parameters, $this->matchParameters($matches[1], $matches[2])); } return $parameters; }
public function matchesUrl($url, $context = array()) { $result = parent::matchesUrl($url, $context); if (!$result) { return $result; } $message = array('This routing rule is deprecated. Please use other rules instead of this.', 'priority' => sfLogger::NOTICE); if (sfContext::hasInstance()) { sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($this, 'application.log', $message)); } return $result; }
/** * Returns true if the URL matches this route, false otherwise. * * @param string $url The URL * @param array $context The context * * @return array An array of parameters */ public function matchesUrl($url, $context = array()) { if (false === ($parameters = parent::matchesUrl($url, $context))) { return false; } if (!isset($this->requirements['sf_method'])) { $this->requirements['sf_method'] = array('get', 'head'); } // enforce the sf_method requirement $methods = is_array($this->requirements['sf_method']) ? $this->requirements['sf_method'] : array($this->requirements['sf_method']); foreach ($methods as $method) { if (0 == strcasecmp($method, $context['method'])) { return $parameters; } } return false; }
public function matchesUrl($url, $context = array()) { $culture = $this->getCulture($context); if (isset($this->requirements['sf_host_culture'])) { $sfHostCulture = $this->requirements['sf_host_culture']; if ($culture != $sfHostCulture) { return false; } } /* if (isset($this->requirements['reviewFilter'])) { $reviewFilter = $this->requirements['reviewFilter']; return parent::matchesUrl(urldecode($url), $context); } */ return parent::matchesUrl(urldecode($url), $context); }
/** * Returns true if the URL matches this route, false otherwise. * * @param string $url The URL * @param array $context The context * * @return array An array of parameters */ public function matchesUrl($url, $context = array()) { $url = aRouteTools::removePageFromUrl($this, $url); return parent::matchesUrl($url, $context); }
$route = new sfRoute('/:foo/:bar', array('bar' => 'foo')); $t->is($route->generate(array('foo' => 'bar')), '/bar', '->generate() generates the shortest URL possible'); $route = new sfRoute('/:foo/:bar', array('bar' => 'foo'), array(), array('generate_shortest_url' => false)); $t->is($route->generate(array('foo' => 'bar')), '/bar/foo', '->generate() generates the longest URL possible if generate_shortest_url is false'); // ->parseStarParameter() $t->diag('->parseStarParameter()'); $route = new sfRoute('/foo/*'); $t->is($route->matchesUrl('/foo/foo/bar/bar/foo'), array('foo' => 'bar', 'bar' => 'foo'), '->parseStarParameter() parses * as key/value pairs'); $t->is($route->matchesUrl('/foo/foo/foo.bar'), array('foo' => 'foo.bar'), '->parseStarParameter() uses / as the key/value separator'); $t->is($route->matchesUrl('/foo'), array(), '->parseStarParameter() returns no additional parameters if the * value is empty'); $route = new sfRoute('/foo/*', array('module' => 'foo')); $t->is($route->matchesUrl('/foo/foo/bar/module/barbar'), array('foo' => 'bar', 'module' => 'foo'), '->parseStarParameter() cannot override a default value'); $route = new sfRoute('/:foo/*'); $t->is($route->matchesUrl('/bar/foo/barbar'), array('foo' => 'bar'), '->parseStarParameter() cannot override pattern variables'); $route = new sfRoute('/foo/*/bar'); $t->is($route->matchesUrl('/foo/foo/bar/bar'), array('foo' => 'bar'), '->parseStarParameter() is able to parse a star in the middle of a rule'); $t->is($route->matchesUrl('/foo/bar'), array(), '->parseStarParameter() is able to parse a star if it is empty'); // ->generateStarParameter() $t->diag('->generateStarParameter()'); $route = new sfRoute('/foo/:foo/*'); $t->is($route->generate(array('foo' => 'bar', 'bar' => 'foo')), '/foo/bar/bar/foo', '->generateStarParameter() replaces * with all the key/pair values that are not variables'); // custom token $t->diag('custom token'); class MyRoute extends sfRoute { protected function tokenizeBufferBefore(&$buffer, &$tokens, &$afterASeparator, &$currentSeparator) { if ($afterASeparator && preg_match('#^=(' . $this->options['variable_regex'] . ')#', $buffer, $match)) { // a labelled variable $this->tokens[] = array('label', $currentSeparator, $match[0], $match[1]); $currentSeparator = '';