Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into rfc/escaper
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 67 changed files with 1,926 additions and 3,123 deletions.
9 changes: 3 additions & 6 deletions src/Exception.php → src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Log;
namespace Zend\Log\Exception;

/**
* @category Zend
* @package Zend_Log
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Exception
{}
interface ExceptionInterface
{}
7 changes: 2 additions & 5 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Log\Exception;

/**
Expand All @@ -35,5 +32,5 @@
*/
class InvalidArgumentException
extends \InvalidArgumentException
implements \Zend\Log\Exception
{}
implements ExceptionInterface
{}
7 changes: 2 additions & 5 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Log\Exception;

/**
Expand All @@ -35,5 +32,5 @@
*/
class RuntimeException
extends \RuntimeException
implements \Zend\Log\Exception
{}
implements ExceptionInterface
{}
9 changes: 3 additions & 6 deletions src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Log;

/**
Expand All @@ -34,8 +31,8 @@ interface Filter
/**
* Returns TRUE to accept the message, FALSE to block it.
*
* @param array $event event data
* @return boolean accepted?
* @param array $event event data
* @return boolean accepted?
*/
public function accept($event);
public function filter(array $event);
}
38 changes: 38 additions & 0 deletions src/Filter/FilterInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Log
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Log\Filter;

/**
* @category Zend
* @package Zend_Log
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface FilterInterface
{
/**
* Returns TRUE to accept the message, FALSE to block it.
*
* @param array $event event data
* @return boolean accepted?
*/
public function filter(array $event);
}
86 changes: 0 additions & 86 deletions src/Filter/Message.php

This file was deleted.

72 changes: 21 additions & 51 deletions src/Filter/Priority.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,89 +19,59 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Log\Filter;

use Zend\Log\Exception;

/**
* @uses \Zend\Log\Exception\InvalidArgumentException
* @uses \Zend\Log\Filter\AbstractFilter
* @category Zend
* @package Zend_Log
* @subpackage Filter
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Priority extends AbstractFilter
class Priority implements FilterInterface
{
/**
* @var integer
* @var int
*/
protected $_priority;
protected $priority;

/**
* @var string
*/
protected $_operator;
protected $operator;

/**
* Filter logging by $priority. By default, it will accept any log
* Filter logging by $priority. By default, it will accept any log
* event whose priority value is less than or equal to $priority.
*
* @param integer $priority Priority
* @param string $operator Comparison operator
* @param int $priority Priority
* @param string $operator Comparison operator
* @return void
* @throws \Zend\Log\Exception\InvalidArgumentException
* @throws Exception\InvalidArgumentException
*/
public function __construct($priority, $operator = null)
{
if (! is_int($priority)) {
throw new \Zend\Log\Exception\InvalidArgumentException('Priority must be an integer');
}

$this->_priority = $priority;
$this->_operator = $operator === null ? '<=' : $operator;
}

/**
* Create a new instance of Zend_Log_Filter_Priority
*
* @param array|\Zend\Config\Config $config
* @return \Zend\Log\Filter\Priority
* @throws \Zend\Log\Exception\InvalidArgumentException
*/
static public function factory($config = array())
{
$config = self::_parseConfig($config);
$config = array_merge(array(
'priority' => null,
'operator' => null,
), $config);

// Add support for constants
if (!is_numeric($config['priority']) && isset($config['priority']) && defined($config['priority'])) {
$config['priority'] = constant($config['priority']);
}

if (!is_numeric($config['priority'])) {
throw new \Zend\Log\Exception\InvalidArgumentException('Priority must be an integer.');
if (!is_int($priority)) {
throw new Exception\InvalidArgumentException(sprintf(
'Priority must be an integer; received "%s"',
gettype($priority)
));
}

return new self(
(int) $config['priority'],
$config['operator']
);
$this->priority = $priority;
$this->operator = $operator === null ? '<=' : $operator;
}

/**
* Returns TRUE to accept the message, FALSE to block it.
*
* @param array $event event data
* @return boolean accepted?
* @param array $event event data
* @return boolean accepted?
*/
public function accept($event)
public function filter(array $event)
{
return version_compare($event['priority'], $this->_priority, $this->_operator);
return version_compare($event['priority'], $this->priority, $this->operator);
}
}
76 changes: 76 additions & 0 deletions src/Filter/Regex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Log
* @subpackage Filter
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Log\Filter;

use Zend\Log\Exception;

/**
* @category Zend
* @package Zend_Log
* @subpackage Filter
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Regex implements FilterInterface
{
/**
* Regex to match
*
* @var string
*/
protected $regex;

/**
* Filter out any log messages not matching the pattern
*
* @param string $regex Regular expression to test the log message
* @throws Exception\InvalidArgumentException
*/
public function __construct($regex)
{
if (@preg_match($regex, '') === false) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid regular expression "%s"',
$regex
));
}
$this->regex = $regex;
}

/**
* Returns TRUE to accept the message, FALSE to block it.
*
* @param array $event event data
* @return boolean accepted?
*/
public function filter(array $event)
{
$message = $event['message'];
if (is_array($event['message'])) {
$message = var_export($message, TRUE);
}
return preg_match($this->regex, $message) > 0;
}
}
Loading

0 comments on commit 8b04bfe

Please sign in to comment.