|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Monolog package. |
|
|
5 |
* |
|
|
6 |
* (c) Jordi Boggiano <j.boggiano@seld.be> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Monolog\Handler; |
|
|
13 |
|
|
|
14 |
/** |
|
|
15 |
* Forwards records to multiple handlers |
|
|
16 |
* |
|
|
17 |
* @author Lenar Lõhmus <lenar@city.ee> |
|
|
18 |
*/ |
|
|
19 |
class GroupHandler extends AbstractHandler |
|
|
20 |
{ |
|
|
21 |
protected $handlers; |
|
|
22 |
|
|
|
23 |
/** |
|
|
24 |
* @param array $handlers Array of Handlers. |
|
|
25 |
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not |
|
|
26 |
*/ |
|
|
27 |
public function __construct(array $handlers, $bubble = true) |
|
|
28 |
{ |
|
|
29 |
foreach ($handlers as $handler) { |
|
|
30 |
if (!$handler instanceof HandlerInterface) { |
|
|
31 |
throw new \InvalidArgumentException('The first argument of the GroupHandler must be an array of HandlerInterface instances.'); |
|
|
32 |
} |
|
|
33 |
} |
|
|
34 |
|
|
|
35 |
$this->handlers = $handlers; |
|
|
36 |
$this->bubble = $bubble; |
|
|
37 |
} |
|
|
38 |
|
|
|
39 |
/** |
|
|
40 |
* {@inheritdoc} |
|
|
41 |
*/ |
|
|
42 |
public function isHandling(array $record) |
|
|
43 |
{ |
|
|
44 |
foreach ($this->handlers as $handler) { |
|
|
45 |
if ($handler->isHandling($record)) { |
|
|
46 |
return true; |
|
|
47 |
} |
|
|
48 |
} |
|
|
49 |
|
|
|
50 |
return false; |
|
|
51 |
} |
|
|
52 |
|
|
|
53 |
/** |
|
|
54 |
* {@inheritdoc} |
|
|
55 |
*/ |
|
|
56 |
public function handle(array $record) |
|
|
57 |
{ |
|
|
58 |
foreach ($this->handlers as $handler) { |
|
|
59 |
$handler->handle($record); |
|
|
60 |
} |
|
|
61 |
|
|
|
62 |
return false === $this->bubble; |
|
|
63 |
} |
|
|
64 |
|
|
|
65 |
/** |
|
|
66 |
* {@inheritdoc} |
|
|
67 |
*/ |
|
|
68 |
public function handleBatch(array $records) |
|
|
69 |
{ |
|
|
70 |
foreach ($this->handlers as $handler) { |
|
|
71 |
$handler->handleBatch($records); |
|
|
72 |
} |
|
|
73 |
} |
|
|
74 |
} |