|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\Security\Http; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\HttpFoundation\RequestMatcherInterface; |
|
|
15 |
use Symfony\Component\HttpFoundation\Request; |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* AccessMap allows configuration of different access control rules for |
|
|
19 |
* specific parts of the website. |
|
|
20 |
* |
|
|
21 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
22 |
*/ |
|
|
23 |
class AccessMap |
|
|
24 |
{ |
|
|
25 |
private $map = array(); |
|
|
26 |
|
|
|
27 |
/** |
|
|
28 |
* Constructor. |
|
|
29 |
* |
|
|
30 |
* @param RequestMatcherInterface $requestMatcher A RequestMatcherInterface instance |
|
|
31 |
* @param array $roles An array of roles needed to access the resource |
|
|
32 |
* @param string|null $channel The channel to enforce (http, https, or null) |
|
|
33 |
*/ |
|
|
34 |
public function add(RequestMatcherInterface $requestMatcher, array $roles = array(), $channel = null) |
|
|
35 |
{ |
|
|
36 |
$this->map[] = array($requestMatcher, $roles, $channel); |
|
|
37 |
} |
|
|
38 |
|
|
|
39 |
public function getPatterns(Request $request) |
|
|
40 |
{ |
|
|
41 |
foreach ($this->map as $elements) { |
|
|
42 |
if (null === $elements[0] || $elements[0]->matches($request)) { |
|
|
43 |
return array($elements[1], $elements[2]); |
|
|
44 |
} |
|
|
45 |
} |
|
|
46 |
|
|
|
47 |
return array(null, null); |
|
|
48 |
} |
|
|
49 |
} |