[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/src/ProxyManager/Generator/Util/ -> IdentifierSuffixer.php (source)

   1  <?php
   2  
   3  declare(strict_types=1);
   4  
   5  namespace ProxyManager\Generator\Util;
   6  
   7  use PackageVersions\Versions;
   8  
   9  /**
  10   * Utility class capable of generating
  11   * valid class/property/method identifiers
  12   * with a deterministic attached suffix,
  13   * in order to prevent property name collisions
  14   * and tampering from userland
  15   *
  16   * @author Marco Pivetta <ocramius@gmail.com>
  17   * @license MIT
  18   */
  19  abstract class IdentifierSuffixer
  20  {
  21      const VALID_IDENTIFIER_FORMAT = '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/';
  22      const DEFAULT_IDENTIFIER = 'g';
  23  
  24      final private function __construct()
  25      {
  26      }
  27  
  28      /**
  29       * Generates a valid unique identifier from the given name,
  30       * with a suffix attached to it
  31       */
  32      public static function getIdentifier(string $name) : string
  33      {
  34          static $salt;
  35  
  36          $salt   = $salt ?? $salt = self::loadBaseHashSalt();
  37          $suffix = \substr(\sha1($name . $salt), 0, 5);
  38  
  39          if (! preg_match(self::VALID_IDENTIFIER_FORMAT, $name)) {
  40              return self::DEFAULT_IDENTIFIER . $suffix;
  41          }
  42  
  43          return $name . $suffix;
  44      }
  45  
  46      private static function loadBaseHashSalt() : string
  47      {
  48          return \sha1(\serialize(Versions::VERSIONS));
  49      }
  50  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1