|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Yaroslav Honcharuk <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Yarhon\RouteGuardBundle\Security\Test; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* AbstractSymfonySecurityTest is a value object class for storing arguments for AuthorizationChecker::isGranted() authorization test. |
|
15
|
|
|
* |
|
16
|
|
|
* Note: we are using \Serializable interface here, because symfony/var-exporter does not |
|
17
|
|
|
* properly handles objects that have properties inherited from parent abstract class. |
|
18
|
|
|
* And since Symfony 4.2 symfony/cache uses symfony/var-exporter to store / retrieve values. |
|
19
|
|
|
* |
|
20
|
|
|
* @see \Symfony\Component\Security\Core\Authorization\AuthorizationChecker::isGranted |
|
21
|
|
|
* |
|
22
|
|
|
* @author Yaroslav Honcharuk <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
abstract class AbstractSymfonySecurityTest implements TestInterface, \Serializable |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $attributes; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var mixed |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $subject; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param array $attributes |
|
38
|
|
|
* @param mixed $subject |
|
39
|
|
|
*/ |
|
40
|
60 |
|
public function __construct(array $attributes, $subject = null) |
|
41
|
|
|
{ |
|
42
|
60 |
|
$this->attributes = $attributes; |
|
43
|
60 |
|
$this->subject = $subject; |
|
44
|
60 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return array |
|
48
|
|
|
*/ |
|
49
|
22 |
|
public function getAttributes() |
|
50
|
|
|
{ |
|
51
|
22 |
|
return $this->attributes; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return mixed |
|
56
|
|
|
*/ |
|
57
|
16 |
|
public function getSubject() |
|
58
|
|
|
{ |
|
59
|
16 |
|
return $this->subject; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
8 |
|
public function serialize() |
|
63
|
|
|
{ |
|
64
|
8 |
|
return serialize([$this->attributes, $this->subject]); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
6 |
|
public function unserialize($data) |
|
68
|
|
|
{ |
|
69
|
6 |
|
list($attributes, $subject) = unserialize($data); |
|
70
|
6 |
|
$this->attributes = $attributes; |
|
71
|
6 |
|
$this->subject = $subject; |
|
72
|
6 |
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|