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

Commit

Permalink
Merge branch 'hotfix/log-cs' of https://github.com/b-durand/zf2 into …
Browse files Browse the repository at this point in the history
…hotfix/log-interfaces
  • Loading branch information
weierophinney committed Jul 5, 2012
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 210 deletions.
38 changes: 0 additions & 38 deletions src/Filter.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Filter/Priority.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Priority implements FilterInterface
*
* @param int $priority Priority
* @param string $operator Comparison operator
* @return void
* @return Priority
* @throws Exception\InvalidArgumentException
*/
public function __construct($priority, $operator = null)
Expand Down
4 changes: 1 addition & 3 deletions src/Filter/Regex.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\Filter;

use Zend\Log\Exception;
Expand All @@ -46,6 +43,7 @@ class Regex implements FilterInterface
* Filter out any log messages not matching the pattern
*
* @param string $regex Regular expression to test the log message
* @return Regex
* @throws Exception\InvalidArgumentException
*/
public function __construct($regex)
Expand Down
3 changes: 2 additions & 1 deletion src/Filter/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class Validator implements FilterInterface
/**
* Filter out any log messages not matching the validator
*
* @param ZendValidator $validator
* @param ZendValidator $validator
* @return Validator
*/
public function __construct(ZendValidator $validator)
{
Expand Down
38 changes: 0 additions & 38 deletions src/Formatter.php

This file was deleted.

8 changes: 3 additions & 5 deletions src/Formatter/ErrorHandler.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\Formatter;

use Zend\Log\Exception;
Expand All @@ -47,8 +44,9 @@ class ErrorHandler implements FormatterInterface
/**
* Class constructor
*
* @param null|string $format Format specifier for log messages
* @throws Zend\Log\Exception\InvalidArgumentException
* @param null|string $format Format specifier for log messages
* @return ErrorHandler
* @throws Exception\InvalidArgumentException
*/
public function __construct($format = null)
{
Expand Down
33 changes: 17 additions & 16 deletions src/Formatter/ExceptionHandler.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\Formatter;

/**
Expand All @@ -36,35 +33,39 @@ class ExceptionHandler implements FormatterInterface
/**
* This method formats the event for the PHP Exception
*
* @param array $event
* @param array $event
* @return string
*/
public function format($event)
{
$output = $event['timestamp'] . ' ' . $event['priorityName'] . ' (' .
$event['priority'] . ') ' . $event['message'] .' in ' .
$event['extra']['file'] . ' on line ' . $event['extra']['line'];
$output = $event['timestamp'] . ' ' . $event['priorityName'] . ' ('
. $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;
$output .= "\n[Trace]\n" . $outputTrace;
}

return $output;
}

/**
* Get the type of a function
*
* @param string $type
* @param string $type
* @return string
*/
protected function getType($type) {
protected function getType($type)
{
switch ($type) {
case "::" :
return "static";
Expand Down
4 changes: 2 additions & 2 deletions src/Formatter/FormatterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ interface FormatterInterface
/**
* Formats data into a single line to be written by the writer.
*
* @param array $event event data
* @return string formatted line to write to the log
* @param array $event event data
* @return string formatted line to write to the log
*/
public function format($event);
}
16 changes: 8 additions & 8 deletions src/Formatter/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ class Simple implements FormatterInterface
/**
* @var string
*/
protected $_format;
protected $format;

const DEFAULT_FORMAT = '%timestamp% %priorityName% (%priority%): %message% %info%';

/**
* Class constructor
*
* @param null|string $format Format specifier for log messages
* @return void
* @throws \Zend\Log\Exception\InvalidArgumentException
* @param null|string $format Format specifier for log messages
* @return Simple
* @throws Exception\InvalidArgumentException
*/
public function __construct($format = null)
{
Expand All @@ -56,18 +56,18 @@ public function __construct($format = null)
throw new Exception\InvalidArgumentException('Format must be a string');
}

$this->_format = $format;
$this->format = $format;
}

/**
* Formats data into a single line to be written by the writer.
*
* @param array $event event data
* @return string formatted line to write to the log
* @param array $event event data
* @return string formatted line to write to the log
*/
public function format($event)
{
$output = $this->_format;
$output = $this->format;

if (!isset($event['info'])) {
$event['info'] = '';
Expand Down
33 changes: 17 additions & 16 deletions src/Formatter/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,24 @@ class Xml implements FormatterInterface
/**
* @var string Name of root element
*/
protected $_rootElement;
protected $rootElement;

/**
* @var array Relates XML elements to log data field keys.
*/
protected $_elementMap;
protected $elementMap;

/**
* @var string Encoding to use in XML
*/
protected $_encoding;
protected $encoding;

/**
* Class constructor
* (the default encoding is UTF-8)
*
* @param array|Traversable $options
* @param array|Traversable $options
* @return Xml
*/
public function __construct($options = array())
{
Expand Down Expand Up @@ -86,11 +87,11 @@ public function __construct($options = array())
$options['encoding'] = 'UTF-8';
}

$this->_rootElement = $options['rootElement'];
$this->rootElement = $options['rootElement'];
$this->setEncoding($options['encoding']);

if (array_key_exists('elementMap', $options)) {
$this->_elementMap = $options['elementMap'];
$this->elementMap = $options['elementMap'];
}
}

Expand All @@ -101,48 +102,48 @@ public function __construct($options = array())
*/
public function getEncoding()
{
return $this->_encoding;
return $this->encoding;
}

/**
* Set encoding
*
* @param string $value
* @return \Zend\Log\Formatter\Xml
* @param string $value
* @return Xml
*/
public function setEncoding($value)
{
$this->_encoding = (string) $value;
$this->encoding = (string) $value;
return $this;
}

/**
* Formats data into a single line to be written by the writer.
*
* @param array $event event data
* @return string formatted line to write to the log
* @param array $event event data
* @return string formatted line to write to the log
*/
public function format($event)
{
if ($this->_elementMap === null) {
if ($this->elementMap === null) {
$dataToInsert = $event;
} else {
$dataToInsert = array();
foreach ($this->_elementMap as $elementName => $fieldKey) {
foreach ($this->elementMap as $elementName => $fieldKey) {
$dataToInsert[$elementName] = $event[$fieldKey];
}
}

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

foreach ($dataToInsert as $key => $value) {
if (empty($value)
|| is_scalar($value)
|| (is_object($value) && method_exists($value,'__toString'))
) {
if($key == "message") {
if ($key == "message") {
$value = htmlspecialchars($value, ENT_COMPAT, $enc);
}
$elt->appendChild(new DOMElement($key, (string)$value));
Expand Down
Loading

0 comments on commit 44df0b2

Please sign in to comment.