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' of git://github.com/zendframework/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
vahid-sohrabloo committed Jul 5, 2012
2 parents f9f4654 + ecdfdf6 commit 0e0780d
Show file tree
Hide file tree
Showing 31 changed files with 209 additions and 331 deletions.
14 changes: 0 additions & 14 deletions .travis/run-tests.sh

This file was deleted.

7 changes: 0 additions & 7 deletions .travis/skipped-components

This file was deleted.

61 changes: 0 additions & 61 deletions .travis/tested-components

This file was deleted.

4 changes: 2 additions & 2 deletions src/Filter/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

namespace Zend\Log\Filter;

use Zend\Log\Exception,
Zend\Validator\ValidatorInterface as ZendValidator;
use Zend\Log\Exception;
use Zend\Validator\ValidatorInterface as ZendValidator;

/**
* @category Zend
Expand Down
8 changes: 4 additions & 4 deletions src/Formatter/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

namespace Zend\Log\Formatter;

use Traversable,
Zend\Stdlib\ArrayUtils,
DOMDocument,
DOMElement;
use Traversable;
use Zend\Stdlib\ArrayUtils;
use DOMDocument;
use DOMElement;

/**
* @category Zend
Expand Down
104 changes: 51 additions & 53 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@

namespace Zend\Log;

use DateTime,
Zend\Stdlib\SplPriorityQueue,
Traversable,
Zend\Loader\Broker,
Zend\Loader\Pluggable,
Zend\Stdlib\ArrayUtils;
use DateTime;
use Zend\Stdlib\SplPriorityQueue;
use Traversable;
use Zend\Stdlib\ArrayUtils;

/**
* Logging messages with a stack of backends
Expand All @@ -35,7 +33,7 @@
* @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 Logger implements LoggerInterface, Pluggable
class Logger implements LoggerInterface
{
/**
* @const int defined from the BSD Syslog message severities
Expand All @@ -52,7 +50,7 @@ class Logger implements LoggerInterface, Pluggable

/**
* The format of the date used for a log entry (ISO 8601 date)
*
*
* @see http://nl3.php.net/manual/en/function.date.php
* @var string
*/
Expand Down Expand Up @@ -82,30 +80,30 @@ class Logger implements LoggerInterface, Pluggable
protected $writers;

/**
* Writer broker
* Writer plugins
*
* @var WriterBroker
* @var WriterPluginManager
*/
protected $writerBroker;
protected $writerPlugins;

/**
* Registered error handler
*
*
* @var boolean
*/
protected static $registeredErrorHandler = false;

/**
* Registered exception handler
*
*
* @var boolean
*/
protected static $registeredExceptionHandler = false;

/**
* Constructor
*
* @todo support configuration (writers, dateTimeFormat, and broker)
* @todo support configuration (writers, dateTimeFormat, and writer plugin manager)
* @return Logger
*/
public function __construct()
Expand Down Expand Up @@ -151,39 +149,39 @@ public function setDateTimeFormat($format)
}

/**
* Get writer broker
* Get writer plugin manager
*
* @see Pluggable::getBroker()
* @return Broker
* @return WriterPluginManager
*/
public function getBroker()
public function getPluginManager()
{
if (null === $this->writerBroker) {
$this->setBroker(new WriterBroker());
if (null === $this->writerPlugins) {
$this->setPluginManager(new WriterPluginManager());
}
return $this->writerBroker;
return $this->writerPlugins;
}

/**
* Set writer broker
* Set writer plugin manager
*
* @param string|Broker $broker
* @param string|WriterPluginManager $plugins
* @return Logger
* @throws Exception\InvalidArgumentException
*/
public function setBroker($broker)
public function setPluginManager($plugins)
{
if (is_string($broker)) {
$broker = new $broker;
if (is_string($plugins)) {
$plugins = new $plugins;
}
if (!$broker instanceof Broker) {
if (!$plugins instanceof WriterPluginManager) {
throw new Exception\InvalidArgumentException(sprintf(
'Writer broker must implement Zend\Loader\Broker; received %s',
is_object($broker) ? get_class($broker) : gettype($broker)
'Writer plugin manager must extend %s\WriterPluginManager; received %s',
__NAMESPACE__,
is_object($plugins) ? get_class($plugins) : gettype($plugins)
));
}

$this->writerBroker = $broker;
$this->writerPlugins = $plugins;
return $this;
}

Expand All @@ -196,7 +194,7 @@ public function setBroker($broker)
*/
public function plugin($name, array $options = null)
{
return $this->getBroker()->load($name, $options);
return $this->getPluginManager()->get($name, $options);
}

/**
Expand All @@ -217,25 +215,25 @@ public function addWriter($writer, $priority=1)
is_object($writer) ? get_class($writer) : gettype($writer)
));
}

$this->writers->insert($writer, $priority);

return $this;
}

/**
* Get writers
*
* @return SplPriorityQueue
*
* @return SplPriorityQueue
*/
public function getWriters()
{
return $this->writers;
}
/**
* Set the writers
*
* @param SplPriorityQueue $writers
*
* @param SplPriorityQueue $writers
* @throws Exception\InvalidArgumentException
* @return Logger
*/
Expand Down Expand Up @@ -285,14 +283,14 @@ public function log($priority, $message, $extra = array())
if ($this->writers->count() === 0) {
throw new Exception\RuntimeException('No log writer specified');
}

$date = new DateTime();
$timestamp = $date->format($this->getDateTimeFormat());

if (is_array($message)) {
$message = var_export($message, true);
}

foreach ($this->writers->toArray() as $writer) {
$writer->write(array(
'timestamp' => $timestamp,
Expand Down Expand Up @@ -385,11 +383,11 @@ public function debug($message, $extra = array())
{
return $this->log(self::DEBUG, $message, $extra);
}

/**
* Register logging system as an error handler to log PHP errors
*
* @link http://www.php.net/manual/en/function.set-error-handler.php
* @link http://www.php.net/manual/en/function.set-error-handler.php
*
* @param Logger $logger
* @return boolean
Expand All @@ -404,7 +402,7 @@ public static function registerErrorHandler(Logger $logger)
if ($logger === null) {
throw new Exception\InvalidArgumentException('Invalid Logger specified');
}

$errorHandlerMap = array(
E_NOTICE => self::NOTICE,
E_USER_NOTICE => self::NOTICE,
Expand All @@ -419,7 +417,7 @@ public static function registerErrorHandler(Logger $logger)
E_DEPRECATED => self::DEBUG,
E_USER_DEPRECATED => self::DEBUG
);

set_error_handler(function($errno, $errstr, $errfile, $errline, $errcontext) use ($errorHandlerMap, $logger) {
$errorLevel = error_reporting();

Expand All @@ -437,7 +435,7 @@ public static function registerErrorHandler(Logger $logger)
}
/**
* Unregister error handler
*
*
*/
public static function unregisterErrorHandler()
{
Expand All @@ -446,27 +444,27 @@ public static function unregisterErrorHandler()
}
/**
* Register logging system as an exception handler to log PHP exceptions
*
*
* @link http://www.php.net/manual/en/function.set-exception-handler.php
*
*
* @param Logger $logger
* @return type
* @return type
*/
public static function registerExceptionHandler(Logger $logger)
{
// Only register once per instance
if (self::$registeredExceptionHandler) {
return false;
}

if ($logger === null) {
throw new Exception\InvalidArgumentException('Invalid Logger specified');
}

set_exception_handler(function ($exception) use ($logger){
$extra = array ('file' => $exception->getFile(),
$extra = array ('file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTrace());
'trace' => $exception->getTrace());
if (isset($exception->xdebug_message)) {
$extra['xdebug'] = $exception->xdebug_message;
}
Expand All @@ -475,7 +473,7 @@ public static function registerExceptionHandler(Logger $logger)
self::$registeredExceptionHandler = true;
return true;
}

/**
* Unregister exception handler
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Writer/AbstractWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

namespace Zend\Log\Writer;

use Zend\Log\Filter,
Zend\Log\Formatter\FormatterInterface as Formatter,
Zend\Log\Exception;
use Zend\Log\Filter;
use Zend\Log\Formatter\FormatterInterface as Formatter;
use Zend\Log\Exception;

/**
* @category Zend
Expand Down
Loading

0 comments on commit 0e0780d

Please sign in to comment.