Nette\DI\PhpReflection::getUseStatements PHP Метод

getUseStatements() публичный статический Метод

public static getUseStatements ( ReflectionClass $class ) : array
$class ReflectionClass
Результат array of [alias => class]
    public static function getUseStatements(\ReflectionClass $class)
    {
        static $cache = [];
        if (!isset($cache[$name = $class->getName()])) {
            if ($class->isInternal()) {
                $cache[$name] = [];
            } else {
                $code = file_get_contents($class->getFileName());
                $cache = self::parseUseStatements($code, $name) + $cache;
            }
        }
        return $cache[$name];
    }

Usage Example

Пример #1
0
 private static function calculateHash($classes, $functions)
 {
     $hash = [];
     foreach ($classes as $name) {
         try {
             $class = new ReflectionClass($name);
         } catch (\ReflectionException $e) {
             return;
         }
         $hash[] = [$name, PhpReflection::getUseStatements($class), $class->isAbstract()];
         foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) {
             if ($prop->getDeclaringClass() == $class) {
                 // intentionally ==
                 $hash[] = [$name, $prop->getName(), $prop->getDocComment()];
             }
         }
         foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
             if ($method->getDeclaringClass() == $class) {
                 // intentionally ==
                 $hash[] = [$name, $method->getName(), $method->getDocComment(), self::hashParameters($method), PHP_VERSION_ID >= 70000 ? $method->getReturnType() : NULL];
             }
         }
     }
     $flip = array_flip($classes);
     foreach ($functions as $name) {
         try {
             $method = strpos($name, '::') ? new ReflectionMethod($name) : new \ReflectionFunction($name);
         } catch (\ReflectionException $e) {
             return;
         }
         $class = $method instanceof ReflectionMethod ? $method->getDeclaringClass() : NULL;
         if ($class && isset($flip[$class->getName()])) {
             continue;
         }
         $hash[] = [$name, $class ? PhpReflection::getUseStatements($method->getDeclaringClass()) : NULL, $method->getDocComment(), self::hashParameters($method), PHP_VERSION_ID >= 70000 ? $method->getReturnType() : NULL];
     }
     return md5(serialize($hash));
 }