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