Skip to content

Commit

Permalink
Fixes coding standards and docblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
b-durand committed Jul 5, 2012
1 parent ddc352d commit ce78f2e
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 57 deletions.
2 changes: 1 addition & 1 deletion library/Zend/Log/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
1 change: 1 addition & 0 deletions library/Zend/Log/Filter/Regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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 library/Zend/Log/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
5 changes: 3 additions & 2 deletions library/Zend/Log/Formatter/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,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
30 changes: 17 additions & 13 deletions library/Zend/Log/Formatter/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,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 library/Zend/Log/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 library/Zend/Log/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 library/Zend/Log/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
29 changes: 20 additions & 9 deletions library/Zend/Log/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,13 @@ public function getWriters()
{
return $this->writers;
}

/**
* Set the writers
*
* @param SplPriorityQueue $writers
* @throws Exception\InvalidArgumentException
* @return Logger
* @throws Exception\InvalidArgumentException
*/
public function setWriters(SplPriorityQueue $writers)
{
Expand All @@ -247,6 +248,7 @@ public function setWriters(SplPriorityQueue $writers)
$this->writers = $writers;
return $this;
}

/**
* Add a message as a log entry
*
Expand Down Expand Up @@ -388,9 +390,9 @@ public function debug($message, $extra = array())
* Register logging system as an error handler to log PHP errors
*
* @link http://www.php.net/manual/en/function.set-error-handler.php
*
* @param Logger $logger
* @return boolean
* @return bool
* @throws Exception\InvalidArgumentException if logger is null
*/
public static function registerErrorHandler(Logger $logger)
{
Expand Down Expand Up @@ -427,12 +429,18 @@ public static function registerErrorHandler(Logger $logger)
} else {
$priority = Logger::INFO;
}
$logger->log($priority, $errstr, array('errno'=>$errno, 'file'=>$errfile, 'line'=>$errline, 'context'=>$errcontext));
$logger->log($priority, $errstr, array(
'errno' => $errno,
'file' => $errfile,
'line' => $errline,
'context' => $errcontext
));
}
});
self::$registeredErrorHandler = true;
return true;
}

/**
* Unregister error handler
*
Expand All @@ -442,13 +450,14 @@ public static function unregisterErrorHandler()
restore_error_handler();
self::$registeredErrorHandler = false;
}

/**
* 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 bool
* @throws Exception\InvalidArgumentException if logger is null
*/
public static function registerExceptionHandler(Logger $logger)
{
Expand All @@ -462,9 +471,11 @@ public static function registerExceptionHandler(Logger $logger)
}

set_exception_handler(function ($exception) use ($logger){
$extra = array ('file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTrace());
$extra = array(
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTrace()
);
if (isset($exception->xdebug_message)) {
$extra['xdebug'] = $exception->xdebug_message;
}
Expand Down
Loading

0 comments on commit ce78f2e

Please sign in to comment.