ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
TestHandler.php
Go to the documentation of this file.
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 
67 {
68  protected $records = array();
69  protected $recordsByLevel = array();
70 
71  public function getRecords()
72  {
73  return $this->records;
74  }
75 
76  public function clear()
77  {
78  $this->records = array();
79  $this->recordsByLevel = array();
80  }
81 
82  protected function hasRecordRecords($level)
83  {
84  return isset($this->recordsByLevel[$level]);
85  }
86 
87  protected function hasRecord($record, $level)
88  {
89  if (is_array($record)) {
90  $record = $record['message'];
91  }
92 
93  return $this->hasRecordThatPasses(function ($rec) use ($record) {
94  return $rec['message'] === $record;
95  }, $level);
96  }
97 
99  {
100  return $this->hasRecordThatPasses(function ($rec) use ($message) {
101  return strpos($rec['message'], $message) !== false;
102  }, $level);
103  }
104 
105  public function hasRecordThatMatches($regex, $level)
106  {
107  return $this->hasRecordThatPasses(function ($rec) use ($regex) {
108  return preg_match($regex, $rec['message']) > 0;
109  }, $level);
110  }
111 
112  public function hasRecordThatPasses($predicate, $level)
113  {
114  if (!is_callable($predicate)) {
115  throw new \InvalidArgumentException("Expected a callable for hasRecordThatSucceeds");
116  }
117 
118  if (!isset($this->recordsByLevel[$level])) {
119  return false;
120  }
121 
122  foreach ($this->recordsByLevel[$level] as $i => $rec) {
123  if (call_user_func($predicate, $rec, $i)) {
124  return true;
125  }
126  }
127 
128  return false;
129  }
130 
134  protected function write(array $record)
135  {
136  $this->recordsByLevel[$record['level']][] = $record;
137  $this->records[] = $record;
138  }
139 
140  public function __call($method, $args)
141  {
142  if (preg_match('/(.*)(Debug|Info|Notice|Warning|Error|Critical|Alert|Emergency)(.*)/', $method, $matches) > 0) {
143  $genericMethod = $matches[1] . 'Record' . $matches[3];
144  $level = constant('Monolog\Logger::' . strtoupper($matches[2]));
145  if (method_exists($this, $genericMethod)) {
146  $args[] = $level;
147 
148  return call_user_func_array(array($this, $genericMethod), $args);
149  }
150  }
151 
152  throw new \BadMethodCallException('Call to undefined method ' . get_class($this) . '::' . $method . '()');
153  }
154 }
hasRecordThatPasses($predicate, $level)
hasRecord($record, $level)
Definition: TestHandler.php:87
Base Handler class providing the Handler structure.
write(array $record)
{}
catch(Exception $e) $message
Create styles array
The data for the language used.
hasRecordThatMatches($regex, $level)
$i
Definition: disco.tpl.php:19
hasRecordThatContains($message, $level)
Definition: TestHandler.php:98
Used for testing purposes.
Definition: TestHandler.php:66