[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/maximebf/debugbar/src/DebugBar/ -> RequestIdGenerator.php (source)

   1  <?php
   2  /*
   3   * This file is part of the DebugBar package.
   4   *
   5   * (c) 2013 Maxime Bouroumeau-Fuseau
   6   *
   7   * For the full copyright and license information, please view the LICENSE
   8   * file that was distributed with this source code.
   9   */
  10  
  11  namespace DebugBar;
  12  
  13  /**
  14   * Basic request ID generator
  15   */
  16  class RequestIdGenerator implements RequestIdGeneratorInterface
  17  {
  18      protected $index = 0;
  19  
  20      /**
  21       * @return string
  22       */
  23      public function generate()
  24      {
  25          if (function_exists('random_bytes')) {
  26              // PHP 7 only
  27              return 'X' . bin2hex(random_bytes(16));
  28          } else if (function_exists('openssl_random_pseudo_bytes')) {
  29              // PHP >= 5.3.0, but OpenSSL may not always be available
  30              return 'X' . bin2hex(openssl_random_pseudo_bytes(16));
  31          } else {
  32              // Fall back to a rudimentary ID generator:
  33              //  * $_SERVER array will make the ID unique to this request.
  34              //  * spl_object_hash($this) will make the ID unique to this object instance.
  35              //    (note that object hashes can be reused, but the other data here should prevent issues here).
  36              //  * uniqid('', true) will use the current microtime(), plus additional random data.
  37              //  * $this->index guarantees the uniqueness of IDs from the current object.
  38              $this->index++;
  39              $entropy = serialize($_SERVER) . uniqid('', true) . spl_object_hash($this) . $this->index;
  40              return 'X' . md5($entropy);
  41          }
  42      }
  43  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer