|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jns\Bundle\XhprofBundle\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use iXHProfRuns; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
8
|
|
|
|
|
9
|
|
|
class XhguiRuns implements iXHProfRuns, ContainerAwareInterface |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var ContainerInterface |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $container; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Sets the Container associated with this Controller. |
|
18
|
|
|
* |
|
19
|
|
|
* @param ContainerInterface $container A ContainerInterface instance |
|
20
|
|
|
*/ |
|
21
|
|
|
public function setContainer(ContainerInterface $container = null) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->container = $container; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function __construct($serverName, $uri) { |
|
27
|
|
|
$this->serverName = $serverName; |
|
|
|
|
|
|
28
|
|
|
$this->uri = $uri; |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* {@inheritDoc} |
|
33
|
|
|
*/ |
|
34
|
|
|
public function get_run($run_id, $type, &$run_desc) { |
|
35
|
|
|
throw new \Exception('not implemented'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritDoc} |
|
40
|
|
|
*/ |
|
41
|
|
|
public function save_run($xhprof_data, $type, $run_id = null) { |
|
42
|
|
|
$pmu = isset($xhprof_data['main()']['pmu']) ? $xhprof_data['main()']['pmu'] : ''; |
|
43
|
|
|
$wt = isset($xhprof_data['main()']['wt']) ? $xhprof_data['main()']['wt'] : ''; |
|
44
|
|
|
$cpu = isset($xhprof_data['main()']['cpu']) ? $xhprof_data['main()']['cpu'] : ''; |
|
45
|
|
|
|
|
46
|
|
|
$doctrine = $this->container->get('doctrine'); |
|
47
|
|
|
if (empty($doctrine)) { |
|
48
|
|
|
throw new \Exception("Trying to save to database, but Doctrine was not set correctly"); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$runId = uniqid(); |
|
52
|
|
|
|
|
53
|
|
|
$em = $doctrine->getManager($this->container->getParameter('jns_xhprof.entity_manager')); |
|
54
|
|
|
$entityClass = $this->container->getParameter('jns_xhprof.entity_class'); |
|
55
|
|
|
|
|
56
|
|
|
$xhprofDetail = new $entityClass(); |
|
57
|
|
|
$xhprofDetail |
|
58
|
|
|
->setId($runId) |
|
59
|
|
|
->setUrl($this->uri) |
|
60
|
|
|
->setCanonicalUrl($this->getCanonicalUrl($this->uri)) |
|
61
|
|
|
->setServerName($this->serverName) |
|
62
|
|
|
->setPerfData(gzcompress(serialize(($xhprof_data)))) |
|
63
|
|
|
->setCookie(serialize($_COOKIE)) |
|
64
|
|
|
->setPost(serialize($_POST)) |
|
65
|
|
|
->setGet(serialize($_GET)) |
|
66
|
|
|
->setPmu($pmu) |
|
67
|
|
|
->setWt($wt) |
|
68
|
|
|
->setCpu($cpu) |
|
69
|
|
|
->setServerId(getenv('SERVER_NAME')) |
|
70
|
|
|
->setAggregateCallsInclude('') |
|
71
|
|
|
->setTimestamp(new \DateTime()) |
|
72
|
|
|
; |
|
73
|
|
|
|
|
74
|
|
|
$em->persist($xhprofDetail); |
|
75
|
|
|
$em->flush(); |
|
76
|
|
|
|
|
77
|
|
|
return $runId; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Return the canonical URL for the passed in one. |
|
82
|
|
|
* |
|
83
|
|
|
* @param String $url |
|
84
|
|
|
* @return String |
|
85
|
|
|
*/ |
|
86
|
|
|
protected function getCanonicalUrl($url) |
|
87
|
|
|
{ |
|
88
|
|
|
if ($url[0] == '#') { |
|
89
|
|
|
$url = substr($url, 1, -1); |
|
90
|
|
|
|
|
91
|
|
|
if (substr($url, -1) == '$') { |
|
92
|
|
|
$url = substr($url, 0, -1); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $url; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
?> |
|
|
|
|
|
|
100
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: