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

Commit

Permalink
Merge branch 'feature/package-logging' of https://github.com/Intiilap…
Browse files Browse the repository at this point in the history
…a/zf2 into feature/logger_dependencies
  • Loading branch information
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 131 deletions.
13 changes: 8 additions & 5 deletions src/Filter/AbstractFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
* @namespace
*/
namespace Zend\Log\Filter;

use Zend\Log\Factory,
Zend\Log\Filter;
Zend\Log\Filter,
Zend\Log\Exception,
Zend\Config\Config;

/**
* @uses \Zend\Log\Exception\InvalidArgumentException
Expand All @@ -41,18 +44,18 @@ abstract class AbstractFilter implements Filter, Factory
/**
* Validate and optionally convert the config to array
*
* @param array|\Zend\Config\Config $config \Zend\Config\Config or Array
* @param array|Config $config Config or Array
* @return array
* @throws \Zend\Log\Exception\InvalidArgumentException
* @throws Exception\InvalidArgumentException
*/
static protected function _parseConfig($config)
{
if ($config instanceof \Zend\Config\Config) {
if ($config instanceof Config) {
$config = $config->toArray();
}

if (!is_array($config)) {
throw new \Zend\Log\Exception\InvalidArgumentException('Configuration must be an array or instance of Zend\Config\Config');
throw new Exception\InvalidArgumentException('Configuration must be an array or instance of Zend\Config\Config');
}

return $config;
Expand Down
8 changes: 5 additions & 3 deletions src/Formatter/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
* @namespace
*/
namespace Zend\Log\Formatter;
use \Zend\Log\Formatter;

use Zend\Log\Formatter,
Zend\Config\Config;

/**
* @uses \Zend\Log\Exception\InvalidArgumentException
Expand Down Expand Up @@ -66,14 +68,14 @@ public function __construct($format = null)
/**
* Factory for Zend_Log_Formatter_Simple classe
*
* @param array|\Zend\Config\Config $options
* @param array|Config $options
* @return \Zend\Log\Formatter\Simple
*/
public static function factory($options = array())
{
$format = null;
if (null !== $options) {
if ($options instanceof Zend\Config\Config) {
if ($options instanceof Config) {
$options = $options->toArray();
}

Expand Down
16 changes: 9 additions & 7 deletions src/Formatter/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
*/
namespace Zend\Log\Formatter;

use \Zend\Log\Formatter,
\Zend\Config\Config;
use Zend\Log\Formatter,
Zend\Config\Config,
DOMDocument,
DOMElement;

/**
* @uses DOMDocument
Expand Down Expand Up @@ -58,7 +60,7 @@ class Xml extends AbstractFormatter
* Class constructor
* (the default encoding is UTF-8)
*
* @param array|\Zend\Config\Config $options
* @param array|Config $options
* @return void
*/
public function __construct($options = array())
Expand Down Expand Up @@ -100,7 +102,7 @@ public function __construct($options = array())
/**
* Factory for Zend_Log_Formatter_Xml classe
*
* @param array|\Zend\Config\Config $options
* @param array|Config $options
* @return \Zend\Log\Formatter\Xml
*/
public static function factory($options = array())
Expand Down Expand Up @@ -148,8 +150,8 @@ public function format($event)
}

$enc = $this->getEncoding();
$dom = new \DOMDocument('1.0', $enc);
$elt = $dom->appendChild(new \DOMElement($this->_rootElement));
$dom = new DOMDocument('1.0', $enc);
$elt = $dom->appendChild(new DOMElement($this->_rootElement));

foreach ($dataToInsert as $key => $value) {
if (empty($value)
Expand All @@ -159,7 +161,7 @@ public function format($event)
if($key == "message") {
$value = htmlspecialchars($value, ENT_COMPAT, $enc);
}
$elt->appendChild(new \DOMElement($key, (string)$value));
$elt->appendChild(new DOMElement($key, (string)$value));
}
}

Expand Down
82 changes: 35 additions & 47 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@
*/
namespace Zend\Log;

use Zend\Config\Config;
use ReflectionClass,
Zend\Config\Config;

/**
* @uses \Zend\Loader
* @uses \Zend\Log\Exception\InvalidArgumentException
* @uses \Zend\Log\Exception\RuntimeException
* @uses \Zend\Log\Filter\Priority
* @category Zend
* @package Zend_Log
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
Expand All @@ -53,12 +50,12 @@ class Logger implements Factory
protected $_priorities = array();

/**
* @var array of \Zend\Log\Writer\AbstractWriter
* @var array of Writer
*/
protected $_writers = array();

/**
* @var array of \Zend\Log\Filter
* @var array of Filter
*/
protected $_filters = array();

Expand All @@ -68,56 +65,49 @@ class Logger implements Factory
protected $_extras = array();

/**
*
* @var string
*/
protected $_defaultWriterNamespace = 'Zend\Log\Writer';

/**
*
* @var string
*/
protected $_defaultFilterNamespace = 'Zend\Log\Filter';

/**
*
* @var string
*/
protected $_defaultFormatterNamespace = 'Zend\Log\Formatter';

/**
*
* @var callback
*/
protected $_origErrorHandler = null;

/**
*
* @var boolean
*/
protected $_registeredErrorHandler = false;

/**
*
* @var array|boolean
*/
protected $_errorHandlerMap = false;

/**
*
* @var string
*/
protected $_timestampFormat = 'c';

/**
* Class constructor. Create a new logger
*
* @param \Zend\Log\Writer\AbstractWriter|null $writer default writer
* @param Writer|null $writer default writer
* @return void
*/
public function __construct(Writer $writer = null)
{
$r = new \ReflectionClass($this);
$r = new ReflectionClass($this);
$this->_priorities = array_flip($r->getConstants());

if ($writer !== null) {
Expand All @@ -129,9 +119,9 @@ public function __construct(Writer $writer = null)
* Factory to construct the logger and one or more writers
* based on the configuration array
*
* @param array|\Zend\Config\Config Array or instance of \Zend\Config\Config
* @throws \Zend\Log\Exception\InvalidArgumentException
* @return \Zend\Log\Logger
* @param array|Config Array or instance of Config
* @throws Exception\InvalidArgumentException
* @return self
*/
static public function factory($config = array())
{
Expand Down Expand Up @@ -168,8 +158,8 @@ static public function factory($config = array())
* Construct a writer object based on a configuration array
*
* @param array $spec config array with writer spec
* @throws \Zend\Log\Exception\InvalidArgumentException
* @return \Zend\Log\Writer\AbstractWriter
* @throws Exception\InvalidArgumentException
* @return Writer
*/
protected function _constructWriterFromConfig($config)
{
Expand Down Expand Up @@ -198,9 +188,9 @@ protected function _constructWriterFromConfig($config)
/**
* Construct filter object from configuration array or Zend_Config object
*
* @param array|\Zend\Config\Config $config \Zend\Config\Config or Array
* @throws \Zend\Log\Exception\InvalidArgumentException
* @return \Zend\Log\Filter
* @param array|Config $config Config or Array
* @throws Exception\InvalidArgumentException
* @return Filter
*/
protected function _constructFilterFromConfig($config)
{
Expand All @@ -219,9 +209,9 @@ protected function _constructFilterFromConfig($config)
/**
* Construct formatter object from configuration array or Zend_Config object
*
* @param array|Zend\Config\Config $config \Zend\Config\Config or Array
* @return \Zend\Log\Formatter
* @throws \Zend\Log\Exception\InvalidArgumentException
* @param array|Config $config Config or Array
* @return Formatter
* @throws Exception\InvalidArgumentException
*/
protected function _constructFormatterFromConfig($config)
{
Expand All @@ -241,9 +231,9 @@ protected function _constructFormatterFromConfig($config)
* Construct a filter or writer from config
*
* @param string $type 'writer' of 'filter'
* @param mixed $config \Zend\Config\Config or Array
* @param mixed $config Config or Array
* @param string $namespace
* @throws \Zend\Log\Exception\InvalidArgumentException
* @throws Exception\InvalidArgumentException
* @return object
*/
protected function _constructFromConfig($type, $config, $namespace)
Expand All @@ -264,7 +254,7 @@ protected function _constructFromConfig($type, $config, $namespace)
\Zend\Loader::loadClass($className);
}

$reflection = new \ReflectionClass($className);
$reflection = new ReflectionClass($className);
if (!$reflection->implementsInterface('Zend\Log\Factory')) {
throw new Exception\InvalidArgumentException(
$className . ' does not implement Zend\Log\Factory and can not be constructed from config.'
Expand All @@ -280,7 +270,7 @@ protected function _constructFromConfig($type, $config, $namespace)
* @param array $config
* @param string $type filter|writer
* @param string $defaultNamespace
* @throws \Zend\Log\Exception\InvalidArgumentException
* @throws Exception\InvalidArgumentException
* @return string full classname
*/
protected function getClassName($config, $type, $defaultNamespace)
Expand Down Expand Up @@ -339,7 +329,7 @@ public function __destruct()
* @param string $method priority name
* @param string $params message to log
* @return void
* @throws \Zend\Log\Exception\InvalidArgumentException
* @throws Exception\InvalidArgumentException
*/
public function __call($method, $params)
{
Expand Down Expand Up @@ -369,8 +359,8 @@ public function __call($method, $params)
* @param string $message Message to log
* @param integer $priority Priority of message
* @param mixed $extras Extra information to log in event
* @throws \Zend\Log\Exception\InvalidArgumentException
* @throws \Zend\Log\Exception\RuntimeException
* @throws Exception\InvalidArgumentException
* @throws Exception\RuntimeException
* @return void
*/
public function log($message, $priority, $extras = null)
Expand Down Expand Up @@ -424,8 +414,8 @@ public function log($message, $priority, $extras = null)
*
* @param string $name Name of priority
* @param integer $priority Numeric priority
* @throws \Zend\Log\Exception\InvalidArgumentException
* @return \Zend\Log\Logger
* @throws Exception\InvalidArgumentException
* @return self
*/
public function addPriority($name, $priority)
{
Expand All @@ -446,18 +436,16 @@ public function addPriority($name, $priority)
* Before a message will be received by any of the writers, it
* must be accepted by all filters added with this method.
*
* @param int|\Zend\Config\Config|\Zend\Log\Filter $filter
* @throws \Zend\Log\Exception\InvalidArgumentException
* @return \Zend\Log\Logger
* @param int|Config|Filter $filter
* @throws Exception\InvalidArgumentException
* @return self
*/
public function addFilter($filter)
{
if (is_int($filter)) {
$filter = new Filter\Priority($filter);

} elseif ($filter instanceof Config || is_array($filter)) {
$filter = $this->_constructFilterFromConfig($filter);

} elseif(! $filter instanceof Filter) {
throw new Exception\InvalidArgumentException('Invalid filter provided');
}
Expand All @@ -470,9 +458,9 @@ public function addFilter($filter)
* Add a writer. A writer is responsible for taking a log
* message and writing it out to storage.
*
* @param mixed $writer \Zend\Log\Writer\AbstractWriter or Config array
* @throws \Zend\Log\Exception\InvalidArgumentException
* @return \Zend\Log\Logger
* @param array|Config|Writer $writer Writer or Config array
* @throws Exception\InvalidArgumentException
* @return self
*/
public function addWriter($writer)
{
Expand All @@ -496,7 +484,7 @@ public function addWriter($writer)
*
* @param string $name Name of the field
* @param string $value Value of the field
* @return \Zend\Log\Logger
* @return self
*/
public function setEventItem($name, $value)
{
Expand All @@ -517,7 +505,7 @@ public function setEventItem($name, $value)
*
* @link http://www.php.net/manual/en/function.set-error-handler.php Custom error handler
*
* @return \Zend\Log\Logger
* @return self
*/
public function registerErrorHandler()
{
Expand Down Expand Up @@ -583,7 +571,7 @@ public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
* Set timestamp format for log entries.
*
* @param string $format
* @return \Zend\Log\Logger
* @return self
*/
public function setTimestampFormat($format)
{
Expand Down
Loading

0 comments on commit 67b60cf

Please sign in to comment.