Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Log / Filter / Regex.php
blob43b3555ec96a7c245d189cb854ee95b37415d065
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Log\Filter;
12 use Traversable;
13 use Zend\Log\Exception;
14 use Zend\Stdlib\ErrorHandler;
16 class Regex implements FilterInterface
18 /**
19 * Regex to match
21 * @var string
23 protected $regex;
25 /**
26 * Filter out any log messages not matching the pattern
28 * @param string|array|Traversable $regex Regular expression to test the log message
29 * @return Regex
30 * @throws Exception\InvalidArgumentException
32 public function __construct($regex)
34 if ($regex instanceof Traversable) {
35 $regex = iterator_to_array($regex);
37 if (is_array($regex)) {
38 $regex = isset($regex['regex']) ? $regex['regex'] : null;
40 ErrorHandler::start(E_WARNING);
41 $result = preg_match($regex, '');
42 $error = ErrorHandler::stop();
43 if ($result === false) {
44 throw new Exception\InvalidArgumentException(sprintf(
45 'Invalid regular expression "%s"',
46 $regex
47 ), 0, $error);
49 $this->regex = $regex;
52 /**
53 * Returns TRUE to accept the message, FALSE to block it.
55 * @param array $event event data
56 * @return bool accepted?
58 public function filter(array $event)
60 $message = $event['message'];
61 if (is_array($event['message'])) {
62 $message = var_export($message, TRUE);
64 return preg_match($this->regex, $message) > 0;