Nette\Reflection\AnnotationsParser::getAll PHP Метод

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

Returns annotations.
public static getAll ( Reflector $r ) : array
$r Reflector
Результат array
    public static function getAll(\Reflector $r)
    {
        if ($r instanceof \ReflectionClass) {
            $type = $r->getName();
            $member = 'class';
            $file = $r->getFileName();
        } elseif ($r instanceof \ReflectionMethod) {
            $type = $r->getDeclaringClass()->getName();
            $member = $r->getName();
            $file = $r->getFileName();
        } elseif ($r instanceof \ReflectionFunction) {
            $type = NULL;
            $member = $r->getName();
            $file = $r->getFileName();
        } else {
            $type = $r->getDeclaringClass()->getName();
            $member = '$' . $r->getName();
            $file = $r->getDeclaringClass()->getFileName();
        }
        if (!self::$useReflection) {
            // auto-expire cache
            if ($file && isset(self::$timestamps[$file]) && self::$timestamps[$file] !== filemtime($file)) {
                unset(self::$cache[$type]);
            }
            unset(self::$timestamps[$file]);
        }
        if (isset(self::$cache[$type][$member])) {
            // is value cached?
            return self::$cache[$type][$member];
        }
        if (self::$useReflection === NULL) {
            // detects whether is reflection available
            self::$useReflection = (bool) ClassType::from(__CLASS__)->getDocComment();
        }
        if (self::$useReflection) {
            $annotations = self::parseComment($r->getDocComment());
        } else {
            $outerCache = self::getCache();
            if (self::$cache === NULL) {
                self::$cache = (array) $outerCache->load('list');
                self::$timestamps = isset(self::$cache['*']) ? self::$cache['*'] : [];
            }
            if (!isset(self::$cache[$type]) && $file) {
                self::$cache['*'][$file] = filemtime($file);
                foreach (static::parsePhp(file_get_contents($file)) as $class => $info) {
                    foreach ($info as $prop => $comment) {
                        if ($prop !== 'use') {
                            self::$cache[$class][$prop] = self::parseComment($comment);
                        }
                    }
                }
                $outerCache->save('list', self::$cache);
            }
            if (isset(self::$cache[$type][$member])) {
                $annotations = self::$cache[$type][$member];
            } else {
                $annotations = [];
            }
        }
        if ($r instanceof \ReflectionMethod && !$r->isPrivate() && (!$r->isConstructor() || !empty($annotations['inheritdoc'][0]))) {
            try {
                $inherited = self::getAll(new \ReflectionMethod(get_parent_class($type), $member));
            } catch (\ReflectionException $e) {
                try {
                    $inherited = self::getAll($r->getPrototype());
                } catch (\ReflectionException $e) {
                    $inherited = [];
                }
            }
            $annotations += array_intersect_key($inherited, array_flip(self::$inherited));
        }
        return self::$cache[$type][$member] = $annotations;
    }

Usage Example

Пример #1
0
 /**
  * Create ProcessSet from given files, optionally filtering by given $groups and $excludeGroups
  *
  * @param Finder $files
  * @param array $groups Groups to be run
  * @param array $excludeGroups Groups to be excluded
  * @param string $filter filter test cases by name
  * @return ProcessSet
  */
 public function createFromFiles(Finder $files, array $groups = null, array $excludeGroups = null, $filter = null)
 {
     $files->sortByName();
     $processSet = $this->getProcessSet();
     if ($groups || $excludeGroups || $filter) {
         $this->output->writeln('Filtering testcases:');
     }
     if ($groups) {
         $this->output->writeln(sprintf(' - by group(s): %s', implode(', ', $groups)));
     }
     if ($excludeGroups) {
         $this->output->writeln(sprintf(' - excluding group(s): %s', implode(', ', $excludeGroups)));
     }
     if ($filter) {
         $this->output->writeln(sprintf(' - by testcase/test name: %s', $filter));
     }
     $testCasesNum = 0;
     foreach ($files as $file) {
         $fileName = $file->getRealpath();
         // Parse classes from the testcase file
         $classes = AnnotationsParser::parsePhp(\file_get_contents($fileName));
         // Get annotations for the first class in testcase (one file = one class)
         $annotations = AnnotationsParser::getAll(new \ReflectionClass(key($classes)));
         // Filter out test-cases having any of excluded groups
         if ($excludeGroups && array_key_exists('group', $annotations) && count($excludingGroups = array_intersect($excludeGroups, $annotations['group']))) {
             if ($this->output->isDebug()) {
                 $this->output->writeln(sprintf('Excluding testcase file %s with group %s', $fileName, implode(', ', $excludingGroups)));
             }
             continue;
         }
         // Filter out test-cases without any matching group
         if ($groups) {
             if (!array_key_exists('group', $annotations) || !count($matchingGroups = array_intersect($groups, $annotations['group']))) {
                 continue;
             }
             if ($this->output->isDebug()) {
                 $this->output->writeln(sprintf('Found testcase file #%d in group %s: %s', ++$testCasesNum, implode(', ', $matchingGroups), $fileName));
             }
         } else {
             if ($this->output->isDebug()) {
                 $this->output->writeln(sprintf('Found testcase file #%d: %s', ++$testCasesNum, $fileName));
             }
         }
         $phpunitArgs = ['--log-junit=logs/' . Strings::webalize(key($classes), null, $lower = false) . '.xml', '--configuration=' . realpath(__DIR__ . '/../phpunit.xml')];
         if ($filter) {
             $phpunitArgs[] = '--filter=' . $filter;
         }
         // If ANSI output is enabled, turn on colors in PHPUnit
         if ($this->output->isDecorated()) {
             $phpunitArgs[] = '--colors=always';
         }
         $processSet->add($this->buildProcess($fileName, $phpunitArgs), key($classes), $delayAfter = !empty($annotations['delayAfter']) ? current($annotations['delayAfter']) : '', $delayMinutes = !empty($annotations['delayMinutes']) ? current($annotations['delayMinutes']) : null);
     }
     return $processSet;
 }
All Usage Examples Of Nette\Reflection\AnnotationsParser::getAll