Skip to content

Commit

Permalink
[HttpFoundation] added support for attributes in RequestMatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Oct 5, 2010
1 parent c0dc01d commit caa9d82
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Symfony/Component/HttpFoundation/RequestMatcher.php
Expand Up @@ -22,6 +22,7 @@ class RequestMatcher implements RequestMatcherInterface
protected $host;
protected $methods;
protected $ip;
protected $attributes = array();

/**
* Adds a check for the URL host name.
Expand Down Expand Up @@ -63,6 +64,17 @@ public function matchMethod($method)
$this->methods = array_map(function ($m) { return strtolower($m); }, is_array($method) ? $method : array($method));
}

/**
* Adds a check for request attribute.
*
* @param string $key The request attribute name
* @param string $regexp A Regexp
*/
public function matchAttribute($key, $regexp)
{
$this->attributes[$key] = $regexp;
}

/**
* {@inheritdoc}
*/
Expand All @@ -72,6 +84,12 @@ public function matches(Request $request)
return false;
}

foreach ($this->attributes as $key => $pattern) {
if (!preg_match($pattern, $request->attributes->get($key))) {
return false;
}
}

if (null !== $this->path && !preg_match($this->path, $request->getPathInfo())) {
return false;
}
Expand Down

0 comments on commit caa9d82

Please sign in to comment.