8000 [HttpFoundation] added support for attributes in RequestMatcher · brtriver/symfony@caa9d82 · GitHub
[go: up one dir, main page]

Skip to content

Commit caa9d82

Browse files
committed
[HttpFoundation] added support for attributes in RequestMatcher
1 parent c0dc01d commit caa9d82

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Symfony/Component/HttpFoundation/RequestMatcher.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class RequestMatcher implements RequestMatcherInterface
2222
protected $host;
2323
protected $methods;
2424
protected $ip;
25+
protected $attributes = array();
2526

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

67+
/**
68+
* Adds a check for request attribute.
69+
*
70+
* @param string $key The request attribute name
71+
* @param string $regexp A Regexp
72+
*/
73+
public function matchAttribute($key, $regexp)
74+
{
75+
$this->attributes[$key] = $regexp;
76+
}
77+
6678
/**
6779
* {@inheritdoc}
6880
*/
@@ -72,6 +84,12 @@ public function matches(Request $request)
7284
return false;
7385
}
7486

87+
foreach ($this->attributes as $key => $pattern) {
88+
if (!preg_match($pattern, $request->attributes->get($key))) {
89+
return false;
90+
}
91+
}
92+
7593
if (null !== $this->path && !preg_match($this->path, $request->getPathInfo())) {
7694
return false;
7795
}

0 commit comments

Comments
 (0)
0