|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the LdapToolsBundle package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Chad Sikorra <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace LdapTools\Bundle\LdapToolsBundle\Log; |
|
12
|
|
|
|
|
13
|
|
|
use LdapTools\Log\LdapLoggerInterface; |
|
14
|
|
|
use LdapTools\Log\LogOperation; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Handles LDAP operation logging for use within the profiler. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Chad Sikorra <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class LdapProfilerLogger implements LdapLoggerInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var LogOperation[] |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $opsByDomain = []; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var LogOperation[] |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $allOperations = []; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var LogOperation[] |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $errors = []; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
|
|
public function start(LogOperation $operation) |
|
42
|
|
|
{ |
|
43
|
|
|
if (!isset($this->opsByDomain[$operation->getDomain()])) { |
|
44
|
|
|
$this->opsByDomain[$operation->getDomain()] = []; |
|
45
|
|
|
} |
|
46
|
|
|
$this->opsByDomain[$operation->getDomain()][] = $operation; |
|
47
|
|
|
$this->allOperations[] = $operation; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritdoc} |
|
52
|
|
|
*/ |
|
53
|
|
|
public function end(LogOperation $operation) |
|
54
|
|
|
{ |
|
55
|
|
|
if (!is_null($operation->getError())) { |
|
56
|
|
|
$this->errors[] = $operation; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get all of the operations recorded by the profiler. Or get the operations for a specific domain. |
|
62
|
|
|
* |
|
63
|
|
|
* @param null|string $domain |
|
64
|
|
|
* @return LogOperation[] |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getOperations($domain = null) |
|
67
|
|
|
{ |
|
68
|
|
|
if (!is_null($domain) && !isset($this->opsByDomain[$domain])) { |
|
69
|
|
|
return []; |
|
70
|
|
|
} elseif (!is_null($domain)) { |
|
71
|
|
|
return $this->opsByDomain[$domain]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $this->allOperations; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Get all the operations that had errors. |
|
79
|
|
|
* |
|
80
|
|
|
* @return LogOperation[] |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getErrors() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->errors; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|