scratch – Blame information for rev 115

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 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 use Monolog\Formatter\FormatterInterface;
15  
16 /**
17 * Forwards records to multiple handlers
18 *
19 * @author Lenar Lõhmus <lenar@city.ee>
20 */
21 class GroupHandler extends AbstractHandler
22 {
23 protected $handlers;
24  
25 /**
26 * @param array $handlers Array of Handlers.
27 * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
28 */
29 public function __construct(array $handlers, $bubble = true)
30 {
31 foreach ($handlers as $handler) {
32 if (!$handler instanceof HandlerInterface) {
33 throw new \InvalidArgumentException('The first argument of the GroupHandler must be an array of HandlerInterface instances.');
34 }
35 }
36  
37 $this->handlers = $handlers;
38 $this->bubble = $bubble;
39 }
40  
41 /**
42 * {@inheritdoc}
43 */
44 public function isHandling(array $record)
45 {
46 foreach ($this->handlers as $handler) {
47 if ($handler->isHandling($record)) {
48 return true;
49 }
50 }
51  
52 return false;
53 }
54  
55 /**
56 * {@inheritdoc}
57 */
58 public function handle(array $record)
59 {
60 if ($this->processors) {
61 foreach ($this->processors as $processor) {
62 $record = call_user_func($processor, $record);
63 }
64 }
65  
66 foreach ($this->handlers as $handler) {
67 $handler->handle($record);
68 }
69  
70 return false === $this->bubble;
71 }
72  
73 /**
74 * {@inheritdoc}
75 */
76 public function handleBatch(array $records)
77 {
78 if ($this->processors) {
79 $processed = array();
80 foreach ($records as $record) {
81 foreach ($this->processors as $processor) {
82 $processed[] = call_user_func($processor, $record);
83 }
84 }
85 $records = $processed;
86 }
87  
88 foreach ($this->handlers as $handler) {
89 $handler->handleBatch($records);
90 }
91 }
92  
93 /**
94 * {@inheritdoc}
95 */
96 public function setFormatter(FormatterInterface $formatter)
97 {
98 foreach ($this->handlers as $handler) {
99 $handler->setFormatter($formatter);
100 }
101  
102 return $this;
103 }
104 }