PageRenderTime 33ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/monica/monica/vendor/zendframework/zendframework/library/Zend/Log/Processor/RequestId.php

https://bitbucket.org/alexandretaz/maniac_divers
PHP | 69 lines | 34 code | 10 blank | 25 comment | 4 complexity | cf6db68afc46fa6d9d3c1d9fb8e21eea MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. namespace Zend\Log\Processor;
  10. use Zend\Console\Console;
  11. class RequestId implements ProcessorInterface
  12. {
  13. /**
  14. * Request identifier
  15. *
  16. * @var string
  17. */
  18. protected $identifier;
  19. /**
  20. * Adds a identifier for the request to the log.
  21. *
  22. * This enables to filter the log for messages belonging to a specific request
  23. *
  24. * @param array $event event data
  25. * @return array event data
  26. */
  27. public function process(array $event)
  28. {
  29. if (!isset($event['extra'])) {
  30. $event['extra'] = array();
  31. }
  32. $event['extra']['requestId'] = $this->getIdentifier();
  33. return $event;
  34. }
  35. /**
  36. * Provide unique identifier for a request
  37. *
  38. * @return string
  39. */
  40. protected function getIdentifier()
  41. {
  42. if ($this->identifier) {
  43. return $this->identifier;
  44. }
  45. $requestTime = (version_compare(PHP_VERSION, '5.4.0') >= 0)
  46. ? $_SERVER['REQUEST_TIME_FLOAT']
  47. : $_SERVER['REQUEST_TIME'];
  48. if (Console::isConsole()) {
  49. $this->identifier = md5($requestTime);
  50. return $this->identifier;
  51. }
  52. if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  53. $this->identifier = md5($requestTime . $_SERVER['HTTP_X_FORWARDED_FOR']);
  54. return $this->identifier;
  55. }
  56. $this->identifier = md5($requestTime . $_SERVER['REMOTE_ADDR']);
  57. return $this->identifier;
  58. }
  59. }