Permalink
Browse files

[#2727] CS review

- Trailing whitespace
- Cache generated value, as it will not change in lifetime of request
  • Loading branch information...
1 parent 8635f0a commit 602858d7306a1d4a4bbc756045885287dff20f3b @weierophinney weierophinney committed Oct 30, 2012
Showing with 25 additions and 9 deletions.
  1. +25 −9 library/Zend/Log/Processor/RequestId.php
@@ -19,17 +19,24 @@
*/
class RequestId implements ProcessorInterface
{
+ /**
+ * Request identifier
+ *
+ * @var string
+ */
+ protected $identifier;
/**
- * Adds a identfier for the request to the log.
+ * Adds a identifier for the request to the log.
+ *
* This enables to filter the log for messages belonging to a specific request
*
* @param array $event event data
* @return array event data
*/
public function process(array $event)
{
- if(!isset($event['extra'])) {
+ if (!isset($event['extra'])) {
$event['extra'] = array();
}
@@ -40,20 +47,29 @@ public function process(array $event)
/**
* Provide unique identifier for a request
*
- * @return array:
+ * @return string
*/
protected function getIdentifier()
{
- $requestTime = (version_compare(PHP_VERSION, '5.4.0') >= 0) ? $_SERVER['REQUEST_TIME_FLOAT'] : $_SERVER['REQUEST_TIME'];
+ if ($this->identifier) {
+ return $this->identifier;
+ }
+
+ $requestTime = (version_compare(PHP_VERSION, '5.4.0') >= 0)
+ ? $_SERVER['REQUEST_TIME_FLOAT']
+ : $_SERVER['REQUEST_TIME'];
- if(Console::isConsole()) {
- return md5($requestTime);
+ if (Console::isConsole()) {
+ $this->identifier = md5($requestTime);
+ return $this->identifier;
}
- if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- return md5($requestTime . $_SERVER['HTTP_X_FORWARDED_FOR']);
+ if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
+ $this->identifier = md5($requestTime . $_SERVER['HTTP_X_FORWARDED_FOR']);
+ return $this->identifier;
}
- return md5($requestTime . $_SERVER['REMOTE_ADDR']);
+ $this->identifier = md5($requestTime . $_SERVER['REMOTE_ADDR']);
+ return $this->identifier;
}
}

0 comments on commit 602858d

Please sign in to comment.