PhpBench\Benchmark\Remote\Reflector::reflect PHP Method

reflect() public method

Return an array of ReflectionClass instances for the given file. The first ReflectionClass is the class contained in the given file (there may be only one) additional ReflectionClass instances are the ancestors of this first class.
public reflect ( string $file ) : ReflectionHierarchy
$file string
return ReflectionHierarchy
    public function reflect($file)
    {
        $classFqn = $this->getClassNameFromFile($file);
        $hierarchy = new ReflectionHierarchy();
        if (null === $classFqn) {
            return $hierarchy;
        }
        $classHierarchy = $this->launcher->payload(__DIR__ . '/template/reflector.template', ['file' => $file, 'class' => $classFqn])->launch();
        foreach ($classHierarchy as $classInfo) {
            $reflectionClass = new ReflectionClass();
            $reflectionClass->class = $classInfo['class'];
            $reflectionClass->abstract = $classInfo['abstract'];
            $reflectionClass->comment = $classInfo['comment'];
            $reflectionClass->interfaces = $classInfo['interfaces'];
            $reflectionClass->path = $file;
            $reflectionClass->namespace = $classInfo['namespace'];
            foreach ($classInfo['methods'] as $methodInfo) {
                $reflectionMethod = new ReflectionMethod();
                $reflectionMethod->reflectionClass = $reflectionClass;
                $reflectionMethod->class = $classInfo['class'];
                $reflectionMethod->name = $methodInfo['name'];
                $reflectionMethod->isStatic = $methodInfo['static'];
                $reflectionMethod->comment = $methodInfo['comment'];
                $reflectionClass->methods[$reflectionMethod->name] = $reflectionMethod;
            }
            $hierarchy->addReflectionClass($reflectionClass);
        }
        return $hierarchy;
    }

Usage Example

Example #1
0
 /**
  * Return a Benchmark instance for the given file or NULL if the
  * given file contains no classes, or the class in the given file is
  * abstract.
  *
  * @param string $file
  *
  * @return Benchmark
  */
 public function getMetadataForFile($file)
 {
     $hierarchy = $this->reflector->reflect($file);
     if ($hierarchy->isEmpty()) {
         return;
     }
     if ($hierarchy->getTop() && true === $hierarchy->getTop()->abstract) {
         return;
     }
     $metadata = $this->driver->getMetadataForHierarchy($hierarchy);
     $this->validateBenchmark($hierarchy, $metadata);
     // validate the subject and load the parameter sets
     foreach ($metadata->getSubjects() as $subject) {
         $this->validateSubject($hierarchy, $subject);
         $paramProviders = $subject->getParamProviders();
         $parameterSets = $this->reflector->getParameterSets($metadata->getPath(), $paramProviders);
         foreach ($parameterSets as $parameterSet) {
             if (!is_array($parameterSet)) {
                 throw new \InvalidArgumentException(sprintf('Each parameter set must be an array, got "%s" for %s::%s', gettype($parameterSet), $metadata->getClass(), $subject->getName()));
             }
         }
         $subject->setParameterSets($parameterSets);
     }
     return $metadata;
 }
All Usage Examples Of PhpBench\Benchmark\Remote\Reflector::reflect