From ab1beeb5c9985bf153abe50e733275c0b4e65689 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 22 Jun 2012 00:36:09 -0500 Subject: [PATCH 1/5] Cleanup - Ensured all file and class level docblocks are correct - Removed all extraneous import statements - Ensured @throws and property annotations are correct --- src/WriterPluginManager.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/WriterPluginManager.php b/src/WriterPluginManager.php index 31382def..65795764 100644 --- a/src/WriterPluginManager.php +++ b/src/WriterPluginManager.php @@ -32,14 +32,7 @@ class WriterPluginManager extends AbstractPluginManager { /** - * Aliases for registered filter invokables - * - * @var array - */ - protected $aliases = array(); - - /** - * Default set of filters + * Default set of writers * * @var array */ @@ -57,12 +50,11 @@ class WriterPluginManager extends AbstractPluginManager /** * Validate the plugin * - * Checks that the filter loaded is either a valid callback or an instance - * of FilterInterface. + * Checks that the writer loaded is an instance of Writer\WriterInterface. * * @param mixed $plugin * @return void - * @throws Exception\RuntimeException if invalid + * @throws Exception\InvalidArgumentException if invalid */ public function validatePlugin($plugin) { From f189854bc41ba13aca65948b648882ad8bffb3e2 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Wed, 4 Jul 2012 08:10:00 +0200 Subject: [PATCH 2/5] Remove old stuff * Remove PHPTools (PHPNamespacer) * Remove zf1 mvc --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 21d57da5..00000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "tools/phptools"] - path = tools/phptools - url = git://github.com/ralphschindler/PHPTools.git From 4ad251e4275906c1f32a5ec6da499d952da537e7 Mon Sep 17 00:00:00 2001 From: Intiilapa Date: Thu, 5 Jul 2012 21:56:34 +0200 Subject: [PATCH 3/5] Fixes typo --- src/Writer/ZendMonitor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Writer/ZendMonitor.php b/src/Writer/ZendMonitor.php index b9ce791d..cbd4097d 100644 --- a/src/Writer/ZendMonitor.php +++ b/src/Writer/ZendMonitor.php @@ -38,7 +38,7 @@ class ZendMonitor extends AbstractWriter protected $isEnabled = true; /** - * Is this for a Zend Server intance? + * Is this for a Zend Server instance? * * @var boolean */ From c777f647a1890fabadf370f1df03694f45cec63f Mon Sep 17 00:00:00 2001 From: Intiilapa Date: Thu, 5 Jul 2012 22:05:14 +0200 Subject: [PATCH 4/5] Fixes coding standards and docblocks --- src/Filter/Priority.php | 2 +- src/Filter/Regex.php | 1 + src/Filter/Validator.php | 3 ++- src/Formatter/ErrorHandler.php | 5 +++-- src/Formatter/ExceptionHandler.php | 30 ++++++++++++++----------- src/Formatter/FormatterInterface.php | 4 ++-- src/Formatter/Simple.php | 16 +++++++------- src/Formatter/Xml.php | 33 ++++++++++++++-------------- src/Logger.php | 29 ++++++++++++++++-------- src/Writer/Db.php | 11 ++++++++-- src/Writer/Mail.php | 6 ++--- 11 files changed, 83 insertions(+), 57 deletions(-) diff --git a/src/Filter/Priority.php b/src/Filter/Priority.php index 577d29f1..565efe42 100644 --- a/src/Filter/Priority.php +++ b/src/Filter/Priority.php @@ -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) diff --git a/src/Filter/Regex.php b/src/Filter/Regex.php index 61ec35b0..93ee6a61 100644 --- a/src/Filter/Regex.php +++ b/src/Filter/Regex.php @@ -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) diff --git a/src/Filter/Validator.php b/src/Filter/Validator.php index 95b0caeb..2df9de90 100644 --- a/src/Filter/Validator.php +++ b/src/Filter/Validator.php @@ -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) { diff --git a/src/Formatter/ErrorHandler.php b/src/Formatter/ErrorHandler.php index 68679461..3dd3bfc6 100644 --- a/src/Formatter/ErrorHandler.php +++ b/src/Formatter/ErrorHandler.php @@ -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) { diff --git a/src/Formatter/ExceptionHandler.php b/src/Formatter/ExceptionHandler.php index 8f3e158c..3962c7a7 100644 --- a/src/Formatter/ExceptionHandler.php +++ b/src/Formatter/ExceptionHandler.php @@ -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"; diff --git a/src/Formatter/FormatterInterface.php b/src/Formatter/FormatterInterface.php index 1aa82870..1e85a95c 100644 --- a/src/Formatter/FormatterInterface.php +++ b/src/Formatter/FormatterInterface.php @@ -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); } diff --git a/src/Formatter/Simple.php b/src/Formatter/Simple.php index 28dec5ba..9e1343cb 100644 --- a/src/Formatter/Simple.php +++ b/src/Formatter/Simple.php @@ -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) { @@ -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'] = ''; diff --git a/src/Formatter/Xml.php b/src/Formatter/Xml.php index 0d69ba22..616eeb4e 100644 --- a/src/Formatter/Xml.php +++ b/src/Formatter/Xml.php @@ -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()) { @@ -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']; } } @@ -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)); diff --git a/src/Logger.php b/src/Logger.php index ad4c2152..914240a4 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -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) { @@ -247,6 +248,7 @@ public function setWriters(SplPriorityQueue $writers) $this->writers = $writers; return $this; } + /** * Add a message as a log entry * @@ -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) { @@ -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 * @@ -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) { @@ -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; } diff --git a/src/Writer/Db.php b/src/Writer/Db.php index c0ff9438..e7e2cd0d 100644 --- a/src/Writer/Db.php +++ b/src/Writer/Db.php @@ -40,7 +40,7 @@ class Db extends AbstractWriter * @var Adapter */ protected $db; - + /** * Table name * @@ -61,7 +61,7 @@ class Db extends AbstractWriter * @var string */ protected $separator = '_'; - + /** * Constructor * @@ -71,6 +71,8 @@ class Db extends AbstractWriter * @param string $tableName * @param array $columnMap * @param string $separator + * @return Db + * @throw Exception\InvalidArgumentException */ public function __construct(Adapter $db, $tableName, array $columnMap = null, $separator = null) { @@ -133,6 +135,7 @@ protected function doWrite(array $event) $statement->execute($dataToInsert); } + /** * Prepare the INSERT SQL statement * @@ -149,6 +152,7 @@ protected function prepareInsert(Adapter $db, $tableName, array $fields) return $sql; } + /** * Map event into column using the $columnMap array * @@ -161,6 +165,7 @@ protected function mapEventIntoColumn(array $event, array $columnMap = null) if (empty($event)) { return array(); } + $data = array(); foreach ($event as $name => $value) { if (is_array($value)) { @@ -175,6 +180,7 @@ protected function mapEventIntoColumn(array $event, array $columnMap = null) } return $data; } + /** * Transform event into column for the db table * @@ -186,6 +192,7 @@ protected function eventIntoColumn(array $event) if (empty($event)) { return array(); } + $data = array(); foreach ($event as $name => $value) { if (is_array($value)) { diff --git a/src/Writer/Mail.php b/src/Writer/Mail.php index 13e0faf6..a50cc54f 100644 --- a/src/Writer/Mail.php +++ b/src/Writer/Mail.php @@ -51,7 +51,6 @@ class Mail extends AbstractWriter */ protected $eventsToMail = array(); - /** * Mail message instance to use * @@ -87,8 +86,9 @@ class Mail extends AbstractWriter /** * Constructor * - * @param MailMessage $mail - * @param Transport\TransportInterface $transport Optional + * @param MailMessage $mail + * @param Transport\TransportInterface $transport Optional + * @return Mail */ public function __construct(MailMessage $mail, Transport\TransportInterface $transport = null) { From c5d3ce33aab3a1709bedb0dbddff56b962ea7f69 Mon Sep 17 00:00:00 2001 From: Intiilapa Date: Thu, 5 Jul 2012 22:14:21 +0200 Subject: [PATCH 5/5] Delete namespace tag --- src/Filter/Regex.php | 3 --- src/Formatter/ErrorHandler.php | 3 --- src/Formatter/ExceptionHandler.php | 3 --- src/LoggerAwareInterface.php | 3 --- src/LoggerInterface.php | 3 --- 5 files changed, 15 deletions(-) diff --git a/src/Filter/Regex.php b/src/Filter/Regex.php index 93ee6a61..f5cd1308 100644 --- a/src/Filter/Regex.php +++ b/src/Filter/Regex.php @@ -19,9 +19,6 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ -/** - * @namespace - */ namespace Zend\Log\Filter; use Zend\Log\Exception; diff --git a/src/Formatter/ErrorHandler.php b/src/Formatter/ErrorHandler.php index 3dd3bfc6..f1d6e964 100644 --- a/src/Formatter/ErrorHandler.php +++ b/src/Formatter/ErrorHandler.php @@ -19,9 +19,6 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ -/** - * @namespace - */ namespace Zend\Log\Formatter; use Zend\Log\Exception; diff --git a/src/Formatter/ExceptionHandler.php b/src/Formatter/ExceptionHandler.php index 3962c7a7..7937d152 100644 --- a/src/Formatter/ExceptionHandler.php +++ b/src/Formatter/ExceptionHandler.php @@ -19,9 +19,6 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ -/** - * @namespace - */ namespace Zend\Log\Formatter; /** diff --git a/src/LoggerAwareInterface.php b/src/LoggerAwareInterface.php index 09785868..cfb2c9fc 100644 --- a/src/LoggerAwareInterface.php +++ b/src/LoggerAwareInterface.php @@ -18,9 +18,6 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ -/** - * @namespace - */ namespace Zend\Log; use Zend\Log\LoggerInterface; diff --git a/src/LoggerInterface.php b/src/LoggerInterface.php index 794e2927..394302b3 100644 --- a/src/LoggerInterface.php +++ b/src/LoggerInterface.php @@ -18,9 +18,6 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ -/** - * @namespace - */ namespace Zend\Log; /**