Completed
Push — refonte ( 2beec9...7b1e92 )
by Arnaud
06:02
created

AdminDataCollector::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace LAG\AdminBundle\Debug\DataCollector;
4
5
use LAG\AdminBundle\Resource\AdminResource;
6
use LAG\AdminBundle\Resource\ResourceCollection;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpFoundation\Response;
9
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
10
11
class AdminDataCollector extends DataCollector
12
{
13
    /**
14
     * @var ResourceCollection
15
     */
16
    private $resourceCollection;
17
18
    /**
19
     * AdminDataCollector constructor.
20
     *
21
     * @param ResourceCollection $resourceCollection
22
     */
23
    public function __construct(ResourceCollection $resourceCollection)
24
    {
25
        $this->resourceCollection = $resourceCollection;
26
    }
27
28
    /**
29
     * @param Request         $request
30
     * @param Response        $response
31
     * @param \Exception|null $exception
32
     */
33
    public function collect(Request $request, Response $response, \Exception $exception = null)
34
    {
35
        $data = [];
36
37
        /** @var AdminResource $resource */
38
        foreach ($this->resourceCollection->all() as $resource) {
39
            $data[$resource->getName()] = [
40
                'entity_class' => $resource->getEntityClass(),
41
                'configuration' => $resource->getConfiguration(),
42
            ];
43
        }
44
        $this->data = $data;
45
    }
46
47
    /**
48
     * Returns the name of the collector.
49
     *
50
     * @return string The collector name
51
     */
52
    public function getName()
53
    {
54
        return 'admin.data_collector';
55
    }
56
57
    public function reset()
58
    {
59
        $this->data = [];
60
    }
61
62
    public function getData()
63
    {
64
        return $this->data;
65
    }
66
}
67