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 Jun 19, 2012
2 parents 61cb196 + e2c2b94 commit f9f4654
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 201 deletions.
30 changes: 0 additions & 30 deletions src/Exception.php

This file was deleted.

8 changes: 1 addition & 7 deletions src/Filter/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,9 @@ class Validator implements FilterInterface
* Filter out any log messages not matching the validator
*
* @param ZendValidator $validator
* @throws Exception\InvalidArgumentException
*/
public function __construct($validator)
public function __construct(ZendValidator $validator)
{
if (!$validator instanceof ZendValidator) {
throw new Exception\InvalidArgumentException(sprintf(
'Expected Zend\Validator object'
));
}
$this->validator = $validator;
}

Expand Down
13 changes: 7 additions & 6 deletions src/Formatter/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ public function format($event)
$event['priority'] . ') ' . $event['message'] .' in ' .
$event['extra']['file'] . ' on line ' . $event['extra']['line'];
if (!empty($event['extra']['trace'])) {
$outputTrace = '';
foreach ($event['extra']['trace'] as $trace) {
$outputTrace = "File : {$trace['file']}\n" .
"Line : {$trace['line']}\n" .
"Func : {$trace['function']}\n" .
"Class : {$trace['class']}\n" .
"Type : " . $this->getType($trace['type']) . "\n" .
"Args : " . print_r($trace['args'], true) . "\n";
$outputTrace .= "File : {$trace['file']}\n" .
"Line : {$trace['line']}\n" .
"Func : {$trace['function']}\n" .
"Class : {$trace['class']}\n" .
"Type : " . $this->getType($trace['type']) . "\n" .
"Args : " . print_r($trace['args'], true) . "\n";
}
$output.= "\n[Trace]\n" . $outputTrace;
}
Expand Down
89 changes: 0 additions & 89 deletions src/LoggableInterface.php

This file was deleted.

7 changes: 2 additions & 5 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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 LoggableInterface, Pluggable
class Logger implements LoggerInterface, Pluggable
{
/**
* @const int defined from the BSD Syslog message severities
Expand Down Expand Up @@ -239,11 +239,8 @@ public function getWriters()
* @throws Exception\InvalidArgumentException
* @return Logger
*/
public function setWriters($writers)
public function setWriters(SplPriorityQueue $writers)
{
if (!$writers instanceof SplPriorityQueue) {
throw new Exception\InvalidArgumentException('Writers must be a SplPriorityQueue of Zend\Log\Writer');
}
foreach ($writers->toArray() as $writer) {
if (!$writer instanceof Writer\WriterInterface) {
throw new Exception\InvalidArgumentException('Writers must be a SplPriorityQueue of Zend\Log\Writer');
Expand Down
39 changes: 0 additions & 39 deletions src/LoggerAware.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/LoggerAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
namespace Zend\Log;

use Zend\Log\Logger;
use Zend\Log\LoggerInterface;

/**
* Logger aware interface
Expand All @@ -35,5 +35,5 @@
*/
interface LoggerAwareInterface
{
public function setLogger(Logger $logger);
public function setLogger(LoggerInterface $logger);
}
2 changes: 1 addition & 1 deletion src/Loggable.php → src/LoggerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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
*/
interface Loggable
interface LoggerInterface
{
/**
* @param string $message
Expand Down
4 changes: 1 addition & 3 deletions src/Writer/AbstractWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ public function addFilter($filter)
{
if (is_int($filter)) {
$filter = new Filter\Priority($filter);
}

if (!$filter instanceof Filter\FilterInterface) {
} elseif (!$filter instanceof Filter\FilterInterface) {
throw new Exception\InvalidArgumentException(sprintf(
'Filter must implement Zend\Log\Filter; received %s',
is_object($filter) ? get_class($filter) : gettype($filter)
Expand Down
6 changes: 0 additions & 6 deletions test/Filter/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
*/
class ValidatorTest extends \PHPUnit_Framework_TestCase
{
public function testRecognizesInvalidValidator()
{
$this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'Expected Zend\Validator object');
new Validator('invalid');
}

public function testValidatorFilter()
{
$filter = new Validator(new Alnum());
Expand Down
59 changes: 46 additions & 13 deletions test/Formatter/ExceptionHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,63 @@ class ExceptionHandlerTest extends \PHPUnit_Framework_TestCase
{
public function testFormat()
{
$date = date('c');
$event = array(
'timestamp' => $date,
'timestamp' => '2012-06-12T09:00:00+02:00',
'message' => 'test',
'priority' => 1,
'priorityName' => 'CRIT',
'extra' => array (
'file' => 'test.php',
'line' => 1,
'trace' => array(array(
'file' => 'test.php',
'line' => 1,
'function' => 'test',
'class' => 'Test',
'type' => '::',
'args' => array(1)
))
'trace' => array(
array(
'file' => 'test.php',
'line' => 1,
'function' => 'test',
'class' => 'Test',
'type' => '::',
'args' => array(1)
),
array(
'file' => 'test.php',
'line' => 2,
'function' => 'test',
'class' => 'Test',
'type' => '::',
'args' => array(1)
)
)
)
);
$expected = <<<EOF
2012-06-12T09:00:00+02:00 CRIT (1) test in test.php on line 1
[Trace]
File : test.php
Line : 1
Func : test
Class : Test
Type : static
Args : Array
(
[0] => 1
)
File : test.php
Line : 2
Func : test
Class : Test
Type : static
Args : Array
(
[0] => 1
)
EOF;

$formatter = new ExceptionHandler();
$output = $formatter->format($event);

$this->assertEquals($date . " CRIT (1) test in test.php on line 1\n" .
"[Trace]\nFile : test.php\nLine : 1\nFunc : test\nClass : Test\n" .
"Type : static\nArgs : Array\n(\n [0] => 1\n)\n\n", $output);
$this->assertEquals($expected, $output);
}
}

0 comments on commit f9f4654

Please sign in to comment.