1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2017 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Jose\Bundle\JoseFramework\DataCollector; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\HttpFoundation\Request; |
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
18
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
19
|
|
|
|
20
|
|
|
final class JoseCollector extends DataCollector |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var Collector[] |
24
|
|
|
*/ |
25
|
|
|
private $collectors = []; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
|
|
public function collect(Request $request, Response $response, \Exception $exception = null) |
31
|
|
|
{ |
32
|
|
|
foreach ($this->collectors as $collector) { |
33
|
|
|
$collector->collect($this->data, $request, $response, $exception); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param Collector $collector |
39
|
|
|
*/ |
40
|
|
|
public function add(Collector $collector) |
41
|
|
|
{ |
42
|
|
|
$this->collectors[$collector->name()] = $collector; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $name |
47
|
|
|
* @param string $method |
48
|
|
|
*/ |
49
|
|
|
public function get(string $name, string $method) |
50
|
|
|
{ |
51
|
|
|
if (!array_key_exists($name, $this->collectors)) { |
52
|
|
|
throw new \InvalidArgumentException(sprintf('No collector with name "%s".', $name)); |
53
|
|
|
} |
54
|
|
|
$collector = $this->collectors[$name]; |
55
|
|
|
if (!method_exists($collector, $method)) { |
56
|
|
|
throw new \InvalidArgumentException(sprintf('The collector with name "%s" has no method "%s".', $name, $method)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $collector->$method($this->data); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function getName() |
66
|
|
|
{ |
67
|
|
|
return 'jose_collector'; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|