-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathZimXhProfBundle.php
51 lines (39 loc) · 1.3 KB
/
ZimXhProfBundle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Zim\XhProfBundle;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class ZimXhProfBundle extends Bundle
{
public static $needToCollect = false;
public function boot()
{
if (
!isset($_ENV['ZIM_XHPROF_ENABLE']) ||
!$_ENV['ZIM_XHPROF_ENABLE'] ||
false === extension_loaded('tideways_xhprof') ||
false === $this->checkCondition()
) {
return;
}
self::$needToCollect = true;
tideways_xhprof_enable(TIDEWAYS_XHPROF_FLAGS_MEMORY);
}
public function checkCondition()
{
if (
!isset($_ENV['ZIM_XHPROF_CONDITION']) ||
!$_ENV['ZIM_XHPROF_CONDITION']
) {
return true;
}
$expressionLanguage = new ExpressionLanguage();
$expressionLanguage->addFunction(ExpressionFunction::fromPhp('array_key_exists', 'key_exists'));
$context = new \stdClass();
$context->get = $_GET;
$context->post = $_POST;
$context->server = $_SERVER;
$context->cookie = $_COOKIE;
return $expressionLanguage->evaluate($_ENV['ZIM_XHPROF_CONDITION'], ['ctx' => $context]);
}
}