1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @project Magento Bridge for Symfony 2. |
5
|
|
|
* |
6
|
|
|
* @author Sébastien MALOT <[email protected]> |
7
|
|
|
* @license MIT |
8
|
|
|
* @url <https://github.com/smalot/magento-bundle> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Smalot\MagentoBundle\DataCollector; |
15
|
|
|
|
16
|
|
|
use Smalot\MagentoBundle\Logger\LoggerInterface; |
17
|
|
|
use Smalot\MagentoBundle\Logger\MagentoLogger; |
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
19
|
|
|
use Symfony\Component\HttpFoundation\Response; |
20
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class MagentoDataCollector |
24
|
|
|
* |
25
|
|
|
* @package Smalot\MagentoBundle\Collector |
26
|
|
|
*/ |
27
|
|
|
class MagentoDataCollector extends DataCollector { |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var MagentoLogger |
31
|
|
|
*/ |
32
|
|
|
protected $logger; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param LoggerInterface $logger |
36
|
|
|
*/ |
37
|
|
|
public function __construct(LoggerInterface $logger) { |
38
|
|
|
$this->logger = $logger; |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param Request $request |
43
|
|
|
* @param Response $response |
44
|
|
|
* @param \Exception $exception |
45
|
|
|
*/ |
46
|
|
|
public function collect(Request $request, Response $response, \Exception $exception = null) { |
47
|
|
|
if ($this->logger) { |
48
|
|
|
$this->data = array('magento' => $this->logger->getCalls()); |
49
|
|
|
} else { |
50
|
|
|
$this->data = array('magento' => array()); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function reset() { |
55
|
|
|
$this->data = array(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Return total duration in seconds. |
60
|
|
|
* |
61
|
|
|
* @return float |
62
|
|
|
*/ |
63
|
|
|
public function getTime() { |
64
|
|
|
$time = 0.0; |
65
|
|
|
|
66
|
|
|
foreach ($this->data['magento'] as $log) { |
67
|
|
|
$time += $log['time']; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $time; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
|
|
public function getCalls() { |
77
|
|
|
$calls = array(); |
78
|
|
|
|
79
|
|
|
foreach ($this->data['magento'] as $call) { |
80
|
|
|
$calls[$call['connection']][] = $call; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $calls; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return int |
88
|
|
|
*/ |
89
|
|
|
public function getCallCount() { |
90
|
|
|
return count($this->data['magento']); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return int |
95
|
|
|
*/ |
96
|
|
|
public function getInvalidEntityCount() { |
97
|
|
|
return 0; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function getName() { |
104
|
|
|
return 'magento'; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.