1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LAG\AdminBundle\Debug\DataCollector; |
6
|
|
|
|
7
|
|
|
use LAG\AdminBundle\Application\Configuration\ApplicationConfiguration; |
8
|
|
|
use LAG\AdminBundle\Request\Extractor\ParametersExtractorInterface; |
9
|
|
|
use LAG\AdminBundle\Resource\Registry\ResourceRegistryInterface; |
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
12
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
13
|
|
|
|
14
|
|
|
class AdminDataCollector extends DataCollector |
15
|
|
|
{ |
16
|
|
|
public function __construct( |
17
|
|
|
private ResourceRegistryInterface $registry, |
18
|
|
|
private ApplicationConfiguration $applicationConfiguration, |
19
|
|
|
private ParametersExtractorInterface $parametersExtractor, |
20
|
1 |
|
) { |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function collect(Request $request, Response $response, \Throwable $exception = null): void |
24
|
|
|
{ |
25
|
1 |
|
$data = [ |
26
|
1 |
|
'resources' => [], |
27
|
1 |
|
'application' => [], |
28
|
1 |
|
]; |
29
|
|
|
|
30
|
1 |
|
foreach ($this->registry->all() as $resource) { |
31
|
|
|
$reflection = new \ReflectionClass($resource); |
32
|
|
|
|
33
|
1 |
|
foreach ($reflection->getProperties() as $reflectionProperty) { |
34
|
|
|
if ($reflectionProperty->isInitialized($resource)) { |
35
|
|
|
$data['resources'][$resource->getName()][$reflectionProperty->getName()] = $reflectionProperty->getValue($resource); |
36
|
|
|
} |
37
|
|
|
} |
38
|
1 |
|
} |
39
|
1 |
|
|
40
|
1 |
|
// When the application configuration is not defined or resolved, we can not access to the admin/menus |
41
|
1 |
|
// configuration |
42
|
|
|
if ($this->applicationConfiguration->isFrozen()) { |
43
|
|
|
$data['application'] = $this->applicationConfiguration->toArray(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
if ($this->parametersExtractor->supports($request)) { |
47
|
1 |
|
$data['application']['resource'] = $this->parametersExtractor->getResourceName($request); |
48
|
1 |
|
$data['application']['operation'] = $this->parametersExtractor->getOperationName($request); |
49
|
1 |
|
} |
50
|
|
|
|
51
|
1 |
|
$this->data = $data; |
52
|
1 |
|
} |
53
|
|
|
|
54
|
1 |
|
public function getName(): string |
55
|
1 |
|
{ |
56
|
|
|
return self::class; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function reset() |
60
|
|
|
{ |
61
|
|
|
$this->data = []; |
62
|
1 |
|
} |
63
|
|
|
|
64
|
1 |
|
public function getData(): array |
65
|
|
|
{ |
66
|
|
|
return $this->data; |
|
|
|
|
67
|
1 |
|
} |
68
|
|
|
} |
69
|
|
|
|