1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rezzza\SecurityBundle\DataCollector; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Annotations\Reader as AnnotationReader; |
6
|
|
|
use Doctrine\Common\Util\ClassUtils; |
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
8
|
|
|
use Symfony\Component\HttpFoundation\Response; |
9
|
|
|
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector as BaseRequestDataCollector; |
10
|
|
|
use Rezzza\SecurityBundle\Controller\Annotations\ObfuscateRequest; |
11
|
|
|
use Rezzza\SecurityBundle\Request\Obfuscator\ObfuscatorInterface; |
12
|
|
|
|
13
|
|
|
class RequestDataCollector extends BaseRequestDataCollector |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var AnnotationReader |
17
|
|
|
*/ |
18
|
|
|
private $annotationReader; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var Obfuscator |
22
|
|
|
*/ |
23
|
|
|
private $obfuscator; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param AnnotationReader $annotationReader annotationReader |
27
|
|
|
* @param ObfuscatorInterface $obfuscator obfuscator |
28
|
|
|
*/ |
29
|
|
|
public function __construct(AnnotationReader $annotationReader, ObfuscatorInterface $obfuscator) |
30
|
|
|
{ |
31
|
|
|
$this->annotationReader = $annotationReader; |
32
|
|
|
$this->obfuscator = $obfuscator; |
|
|
|
|
33
|
|
|
|
34
|
|
|
parent::__construct(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function collect(Request $request, Response $response, \Exception $exception = null) |
38
|
|
|
{ |
39
|
|
|
parent::collect($request, $response, $exception); |
40
|
|
|
|
41
|
|
|
$controller = explode('::', $request->get('_controller')); |
42
|
|
|
|
43
|
|
|
if (count($controller) !== 2) { |
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$class = new \ReflectionClass($controller[0]); |
48
|
|
|
$reflectionMethod = $class->getMethod($controller[1]); |
49
|
|
|
$annotation = $this->annotationReader->getMethodAnnotation($reflectionMethod, '\Rezzza\SecurityBundle\Controller\Annotations\ObfuscateRequest'); |
50
|
|
|
|
51
|
|
|
if ($annotation) { |
52
|
|
|
$this->data = $this->obfuscator->obfuscate($this->data, $annotation->getObfuscatedPatterns()); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..