本文整理汇总了PHP中sfRoute::matchesUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP sfRoute::matchesUrl方法的具体用法?PHP sfRoute::matchesUrl怎么用?PHP sfRoute::matchesUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfRoute
的用法示例。
在下文中一共展示了sfRoute::matchesUrl方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: matchesUrl
/**
* 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;
}
示例2: matchesUrl
/**
* @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;
}
示例3: matchesUrl
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;
}
示例4: matchesUrl
/**
* 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;
}
示例5: matchesUrl
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);
}
示例6: matchesUrl
/**
* 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);
}
示例7: tokenizeBufferBefore
$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 = '';