[ Index ]

PHP Cross Reference of phpBB-3.3.12-deutsch

title

Body

[close]

/vendor/zendframework/zend-code/src/Scanner/ -> Util.php (source)

   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-2016 Zend Technologies USA Inc. (http://www.zend.com)
   7   * @license   http://framework.zend.com/license/new-bsd New BSD License
   8   */
   9  
  10  namespace Zend\Code\Scanner;
  11  
  12  use stdClass;
  13  use Zend\Code\Exception;
  14  
  15  use function array_key_exists;
  16  use function is_object;
  17  use function ltrim;
  18  use function property_exists;
  19  use function sprintf;
  20  use function strlen;
  21  use function strpos;
  22  use function substr;
  23  use function substr_replace;
  24  
  25  /**
  26   * Shared utility methods used by scanners
  27   */
  28  class Util
  29  {
  30      /**
  31       * Resolve imports
  32       *
  33       * @param  string $value
  34       * @param  null|string $key
  35       * @param  \stdClass $data
  36       * @return void
  37       * @throws Exception\InvalidArgumentException
  38       */
  39      public static function resolveImports(&$value, $key = null, stdClass $data = null)
  40      {
  41          if (! is_object($data)
  42              || ! property_exists($data, 'uses')
  43              || ! property_exists($data, 'namespace')
  44          ) {
  45              throw new Exception\InvalidArgumentException(sprintf(
  46                  '%s expects a data object containing "uses" and "namespace" properties; on or both missing',
  47                  __METHOD__
  48              ));
  49          }
  50  
  51          if ($data->namespace && ! $data->uses && strlen($value) > 0 && $value[0] != '\\') {
  52              $value = $data->namespace . '\\' . $value;
  53  
  54              return;
  55          }
  56  
  57          if (! $data->uses || strlen($value) <= 0 || $value[0] == '\\') {
  58              $value = ltrim($value, '\\');
  59  
  60              return;
  61          }
  62  
  63          if ($data->namespace || $data->uses) {
  64              $firstPart = $value;
  65              if (($firstPartEnd = strpos($firstPart, '\\')) !== false) {
  66                  $firstPart = substr($firstPart, 0, $firstPartEnd);
  67              } else {
  68                  $firstPartEnd = strlen($firstPart);
  69              }
  70  
  71              if (array_key_exists($firstPart, $data->uses)) {
  72                  $value = substr_replace($value, $data->uses[$firstPart], 0, $firstPartEnd);
  73  
  74                  return;
  75              }
  76  
  77              if ($data->namespace) {
  78                  $value = $data->namespace . '\\' . $value;
  79  
  80                  return;
  81              }
  82          }
  83      }
  84  }


Generated: Sun Jun 23 12:25:44 2024 Cross-referenced by PHPXref 0.7.1