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 ValidatorMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 43 changed files with 110 additions and 152 deletions.
2 changes: 1 addition & 1 deletion src/Formatter/ErrorHandler.php
Expand Up @@ -44,7 +44,7 @@ public function format($event)
* @param string $key
* @return array
*/
protected function buildReplacementsFromArray ($event, $key = null)
protected function buildReplacementsFromArray($event, $key = null)
{
$result = array();
foreach ($event as $index => $value) {
Expand Down
8 changes: 4 additions & 4 deletions src/Logger.php
Expand Up @@ -123,7 +123,7 @@ class Logger implements LoggerInterface
* @return Logger
* @throws Exception\InvalidArgumentException
*/
public function __construct(array $options = null)
public function __construct($options = null)
{
$this->writers = new SplPriorityQueue();

Expand Down Expand Up @@ -154,6 +154,8 @@ public function __construct(array $options = null)
static::registerErrorHandler($this);
}

} elseif ($options) {
throw new Exception\InvalidArgumentException('Options must be an array or an object implementing \Traversable ');
}

$this->processors = new SplPriorityQueue();
Expand Down Expand Up @@ -519,9 +521,7 @@ public static function registerErrorHandler(Logger $logger, $continueNativeHandl

$errorPriorityMap = static::$errorPriorityMap;

$previous = set_error_handler(function ($level, $message, $file, $line)
use ($logger, $errorPriorityMap, $continueNativeHandler)
{
$previous = set_error_handler(function ($level, $message, $file, $line) use ($logger, $errorPriorityMap, $continueNativeHandler) {
$iniLevel = error_reporting();

if ($iniLevel & $level) {
Expand Down
35 changes: 34 additions & 1 deletion src/LoggerAbstractServiceFactory.php
Expand Up @@ -56,7 +56,9 @@ public function canCreateServiceWithName(ServiceLocatorInterface $services, $nam
public function createServiceWithName(ServiceLocatorInterface $services, $name, $requestedName)
{
$config = $this->getConfig($services);
return new Logger($config[$requestedName]);
$config = $config[$requestedName];
$this->processConfig($config, $services);
return new Logger($config);
}

/**
Expand Down Expand Up @@ -85,4 +87,35 @@ protected function getConfig(ServiceLocatorInterface $services)
$this->config = $config[$this->configKey];
return $this->config;
}

protected function processConfig(&$config, ServiceLocatorInterface $services)
{
if (!isset($config['writers'])) {
return;
}

foreach ($config['writers'] as $index => $writerConfig) {
if (!isset($writerConfig['name'])
|| strtolower($writerConfig['name']) != 'db'
) {
continue;
}
if (!isset($writerConfig['options'])
|| !isset($writerConfig['options']['db'])
) {
continue;
}
if (!is_string($writerConfig['options']['db'])) {
continue;
}
if (!$services->has($writerConfig['options']['db'])) {
continue;
}

// Retrieve the DB service from the service locator, and
// inject it into the configuration.
$db = $services->get($writerConfig['options']['db']);
$config['writers'][$index]['options']['db'] = $db;
}
}
}
6 changes: 3 additions & 3 deletions src/Writer/MongoDB.php
Expand Up @@ -55,7 +55,7 @@ public function __construct($mongo, $database = null, $collection = null, array
}
if (is_array($mongo)) {
parent::__construct($mongo);
$saveOptions = isset($mongo['save_options']) ? $mongo['save_options'] : null;
$saveOptions = isset($mongo['save_options']) ? $mongo['save_options'] : array();
$collection = isset($mongo['collection']) ? $mongo['collection'] : null;
$database = isset($mongo['database']) ? $mongo['database'] : null;
$mongo = isset($mongo['mongo']) ? $mongo['mongo'] : null;
Expand All @@ -74,10 +74,10 @@ public function __construct($mongo, $database = null, $collection = null, array
}

if (!($mongo instanceof MongoClient || $mongo instanceof Mongo)) {
throw new Exception\InvalidArgumentException(
throw new Exception\InvalidArgumentException(sprintf(
'Parameter of type %s is invalid; must be MongoClient or Mongo',
(is_object($mongo) ? get_class($mongo) : gettype($mongo))
);
));
}

$this->mongoCollection = $mongo->selectCollection($database, $collection);
Expand Down
4 changes: 0 additions & 4 deletions test/Filter/MockTest.php
Expand Up @@ -5,17 +5,13 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Log
*/

namespace ZendTest\Log\Filter;

use Zend\Log\Filter\Mock as MockFilter;

/**
* @category Zend
* @package Zend_Log
* @subpackage UnitTests
* @group Zend_Log
*/
class MockTest extends \PHPUnit_Framework_TestCase
Expand Down
4 changes: 0 additions & 4 deletions test/Filter/PriorityTest.php
Expand Up @@ -5,17 +5,13 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Log
*/

namespace ZendTest\Log\Filter;

use Zend\Log\Filter\Priority;

/**
* @category Zend
* @package Zend_Log
* @subpackage UnitTests
* @group Zend_Log
*/
class PriorityTest extends \PHPUnit_Framework_TestCase
Expand Down
4 changes: 0 additions & 4 deletions test/Filter/RegexTest.php
Expand Up @@ -5,17 +5,13 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Log
*/

namespace ZendTest\Log\Filter;

use Zend\Log\Filter\Regex;

/**
* @category Zend
* @package Zend_Log
* @subpackage UnitTests
* @group Zend_Log
*/
class RegexTest extends \PHPUnit_Framework_TestCase
Expand Down
4 changes: 0 additions & 4 deletions test/Filter/SuppressFilterTest.php
Expand Up @@ -5,17 +5,13 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Log
*/

namespace ZendTest\Log\Filter;

use Zend\Log\Filter\SuppressFilter;

/**
* @category Zend
* @package Zend_Log
* @subpackage UnitTests
* @group Zend_Log
*/
class SuppressFilterTest extends \PHPUnit_Framework_TestCase
Expand Down
8 changes: 2 additions & 6 deletions test/Filter/ValidatorTest.php
Expand Up @@ -5,20 +5,16 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Log
*/

namespace ZendTest\Log\Filter;

use Zend\Log\Filter\Validator;
use Zend\Validator\ValidatorChain;
use Zend\Validator\Digits as DigitsFilter;
use Zend\I18n\Validator\Int;
use Zend\Validator\NotEmpty as NotEmptyFilter;

/**
* @category Zend
* @package Zend_Log
* @subpackage UnitTests
* @group Zend_Log
*/
class ValidatorTest extends \PHPUnit_Framework_TestCase
Expand All @@ -35,8 +31,8 @@ public function testValidatorFilter()
public function testValidatorChain()
{
$validatorChain = new ValidatorChain();
$validatorChain->attach(new NotEmptyFilter());
$validatorChain->attach(new DigitsFilter());
$validatorChain->attach(new Int());
$filter = new Validator($validatorChain);
$this->assertTrue($filter->filter(array('message' => '123')));
$this->assertFalse($filter->filter(array('message' => 'test')));
Expand Down
32 changes: 20 additions & 12 deletions test/Formatter/BaseTest.php
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Log
*/

namespace ZendTest\Log\Formatter;
Expand All @@ -18,9 +17,6 @@
use Zend\Log\Formatter\Base as BaseFormatter;

/**
* @category Zend
* @package Zend_Log
* @subpackage UnitTests
* @group Zend_Log
*/
class BaseTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -138,14 +134,26 @@ public function testFormatNoInfiniteLoopOnSelfReferencingArrayValues()
'selfRefArr' => $selfRefArr,
),
);
$outputExpected = array(
'timestamp' => $datetime->format($formatter->getDateTimeFormat()),
'priority' => 1,
'message' => 'tottakai',
'extra' => array(
'selfRefArr' => '{"selfRefArr":{"selfRefArr":null}}',
),
);

if (version_compare(PHP_VERSION, '5.5', 'lt')) {
$outputExpected = array(
'timestamp' => $datetime->format($formatter->getDateTimeFormat()),
'priority' => 1,
'message' => 'tottakai',
'extra' => array(
'selfRefArr' => '{"selfRefArr":{"selfRefArr":null}}',
),
);
} else {
$outputExpected = array(
'timestamp' => $datetime->format($formatter->getDateTimeFormat()),
'priority' => 1,
'message' => 'tottakai',
'extra' => array(
'selfRefArr' => '',
),
);
}

$this->assertEquals($outputExpected, $formatter->format($event));
}
Expand Down
4 changes: 0 additions & 4 deletions test/Formatter/DbTest.php
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Log
*/

namespace ZendTest\Log\Formatter;
Expand All @@ -14,9 +13,6 @@
use Zend\Log\Formatter\Db as DbFormatter;

/**
* @category Zend
* @package Zend_Log
* @subpackage UnitTests
* @group Zend_Log
*/
class DbTest extends \PHPUnit_Framework_TestCase
Expand Down
4 changes: 0 additions & 4 deletions test/Formatter/ErrorHandlerTest.php
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Log
*/

namespace ZendTest\Log\Formatter;
Expand All @@ -16,9 +15,6 @@
use ZendTest\Log\TestAsset\NotStringObject;

/**
* @category Zend
* @package Zend_Log
* @subpackage UnitTests
* @group Zend_Log
*/
class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
Expand Down
4 changes: 0 additions & 4 deletions test/Formatter/ExceptionHandlerTest.php
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Log
*/

namespace ZendTest\Log\Formatter;
Expand All @@ -14,9 +13,6 @@
use Zend\Log\Formatter\ExceptionHandler;

/**
* @category Zend
* @package Zend_Log
* @subpackage UnitTests
* @group Zend_Log
*/
class ExceptionHandlerTest extends \PHPUnit_Framework_TestCase
Expand Down
6 changes: 0 additions & 6 deletions test/Formatter/FirePhpTest.php
Expand Up @@ -3,9 +3,6 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @category Zend
* @package Zend_Log
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
Expand All @@ -15,9 +12,6 @@
use Zend\Log\Formatter\FirePhp;

/**
* @category Zend
* @package Zend_Log
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @group Zend_Log
Expand Down
4 changes: 0 additions & 4 deletions test/Formatter/SimpleTest.php
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Log
*/

namespace ZendTest\Log\Formatter;
Expand All @@ -15,9 +14,6 @@
use RuntimeException;

/**
* @category Zend
* @package Zend_Log
* @subpackage UnitTests
* @group Zend_Log
*/
class SimpleTest extends \PHPUnit_Framework_TestCase
Expand Down
4 changes: 0 additions & 4 deletions test/Formatter/XmlTest.php
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Log
*/

namespace ZendTest\Log\Formatter;
Expand All @@ -15,9 +14,6 @@
use Zend\Log\Formatter\Xml as XmlFormatter;

/**
* @category Zend
* @package Zend_Log
* @subpackage UnitTests
* @group Zend_Log
*/
class XmlTest extends \PHPUnit_Framework_TestCase
Expand Down

0 comments on commit a18fe5d

Please sign in to comment.