Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[#2727] CS review

- Trailing whitespace
- Cache generated value, as it will not change in lifetime of request
  • Loading branch information...
commit 602858d7306a1d4a4bbc756045885287dff20f3b 1 parent 8635f0a
@weierophinney weierophinney authored
Showing with 25 additions and 9 deletions.
  1. +25 −9 library/Zend/Log/Processor/RequestId.php
View
34 library/Zend/Log/Processor/RequestId.php
@@ -19,9 +19,16 @@
*/
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
@@ -29,7 +36,7 @@ class RequestId implements ProcessorInterface
*/
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;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.