Extract the annotations from a class.

@param string $class
@param bool $withParents

@throws \L\Annotation\Exception

@return array
505899
public static function fromClass(
        string $class,
        bool $withParents = false
    ): array
    {
        try {

            $class = new \ReflectionClass($class);
        }
        catch (\ReflectionException $e) {

            throw new Exception(
                "Class '{$class}' not found.",
                Exception::CLASS_NOT_FOUND
            );
        }

        $docComment = $class->getDocComment();

        if ($withParents) {

            while (1) {

                if ($class = $class->getParentClass()) {

                    if ($parentDoc = $class->getDocComment()) {

                        $docComment = $docComment === false ?
                            $parentDoc :
                            "{$parentDoc}{$docComment}";
                    }
                }
                else {

                    break;
                }
            }
        }

        unset($class);

        if ($docComment === false) {

            return [];
        }

        return Parser::parseDocComment($docComment);
    }
879994
public function getParent(ClassMetadata $class)
    {
        $className = $class->getName();
        if (!class_exists($className) || (!$parent = get_parent_class($className))) {
            return null;
        }

        return $this->getClassByName($parent);
    }
1091463
public function parse(RefClass $class)
    {
        $result = [];

        $annotations = $this->parseComment($class->docComment);
        foreach ($annotations as $annotation) {
            $annotation->originClass = $class->name;
            $result[]                = $annotation;
        }

        foreach ($class->constants as $constant) {
            foreach ($this->parseComment($constant->docComment) as $annotation) {
                $annotation->originClass    = $class->name;
                $annotation->originConstant = $constant->name;
                $result[]                   = $annotation;
            }
        }

        foreach ($class->properties as $property) {
            foreach ($this->parseComment($property->docComment) as $annotation) {
                $annotation->originClass    = $class->name;
                $annotation->originProperty = $property->name;
                $result[]                   = $annotation;
            }
        }

        foreach ($class->methods as $method) {
            foreach ($this->parseComment($method->docComment) as $annotation) {
                $annotation->originClass  = $class->name;
                $annotation->originMethod = $method->name;
                $result[]                 = $annotation;
            }
        }

        return $result;
    }
699605
private function getParentFields(ClassMetadata $class, $fields = array())
    {
        if ($parent = $this->classStore->getParent($class)) {
            $parentFields = $parent->getFieldNames();

            foreach ($parentFields as $field) {
                if (!in_array($field, $fields)) {
                    $fields[] = $field;
                }
            }

            $fields = $this->getParentFields($parent, $fields);
        }

        return $fields;
    }
1323639
public function getClassNames ( $withNamespace = true ) {
        $tokens = new \PHP_Token_Stream($this->_content);
        $classes = $tokens->getClasses();
        $classNames = array();
        foreach ( $classes as $className => $class ) {
            $namespace = $class['package']['namespace'];
            if ( $withNamespace === true && $namespace !== '' ) {
                $className = $namespace . '\\' . $className;
            }
            $classNames[] = $className;
        }
        return $classNames;
    }
1038626
public static function getParentClasses($className) {
        $result = array();
        $class = new \ReflectionClass($className);
        if( false === $class ) {
            return $result;
        }
        do {
            $name = $class->getName();
            $result[] = $name;
            $class = $class->getParentClass();
        } while( false !== $class );
        return $result;
    }
422888
public function getDescendantsOf($class)
    {
        if (is_object($class)) {
            $class = get_class($class);
        }

        $lClass = strtolower($class);
        if (array_key_exists($lClass, $this->descendants)) {
            return $this->descendants[$lClass];
        }

        return [];
    }
540548
public static function getAnnotationPoints($annotationClassName, $where = null)
    {
        if(null === $where)
        {
            return array_merge(
                static::$annotationRelation[$annotationClassName]['Class'] ?? [],
                static::$annotationRelation[$annotationClassName]['Method'] ?? [],
                static::$annotationRelation[$annotationClassName]['Property'] ?? []
            );
        }
        else
        {
            return static::$annotationRelation[$annotationClassName][$where] ?? [];
        }
    }
602565
public function extractName($class)
    {
        foreach ($this->extractors as $extractor) {
            if ($extractor->canExtractName($class)) {
                return $extractor->extractName($class);
            }
        }

        throw new \InvalidArgumentException();
    }
498604
protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonSuperclassParents = [])
    {
        /** @var $class ClassMetadata */
        /** @var $parent ClassMetadata */
        if ($parent) {
            $this->addInheritedIndexes($class, $parent);
            $this->addInheritedAttributes($class, $parent);

            $class->setInheritanceType($parent->inheritanceType);
            $class->setDiscriminatorAttribute($parent->discriminatorAttribute);
            $class->setDiscriminatorMap($parent->discriminatorMap);
            $class->setDiscriminatorDefaultValue($parent->discriminatorDefaultValue);
            $class->setVersioned($parent->isVersioned);
            $class->setVersionAttribute($parent->versionAttribute);
            $class->setLifecycleCallbacks($parent->lifecycleCallbacks);
            $class->setAlsoLoadMethods($parent->alsoLoadMethods);
            $class->setChangeTrackingPolicy($parent->changeTrackingPolicy);

            if ($parent->isMappedSuperclass) {
                $class->setCustomRepositoryClass($parent->customRepositoryClassName);
            }
        }

        // Invoke driver
        try {
            $this->driver->loadMetadataForClass($class->getName(), $class);
        } catch (\ReflectionException $e) {
            throw MappingException::reflectionFailure($class->getName(), $e);
        }

        if (!$class->getIndex() && !$class->isMappedSuperclass && !$class->isEmbeddedDocument) {
            throw MappingException::hashKeyRequired($class->name);
        }

        $class->setParentClassNames($nonSuperclassParents);

        if ($parent) {
            if ($parent->isInheritanceTypeSingleTable()) {
                $class->setTable($parent->getTableName());
                $class->setRequireIndexes($parent->requireIndexes);
            } elseif ($class->requireIndexes === null) {
                $class->setRequireIndexes($parent->requireIndexes);
            }
        }

        if ($this->evm->hasListeners(Event::loadClassMetadata)) {
            $eventArgs = new LoadClassMetadataEventArgs($class, $this->dm);
            $this->evm->dispatchEvent(Event::loadClassMetadata, $eventArgs);
        }
    }
767326
public static function getClassParameters(string $class, bool $toArray = false): array
    {
        if (!\class_exists($class)) {
            throw new \InvalidArgumentException("Class not exists: {$class} (autoloading failed)");
        }

        $reflection = new \ReflectionClass($class);

        if (!$reflection->isInstantiable()) {
            throw new \InvalidArgumentException("Unable to create instance of abstract class: {$class}");
        }

        $params = $reflection->getConstructor()->getParameters();

        if ($params === []) {
            return [];
        }

        if (!$toArray) {
            return $params;
        }

        return static::reflectionParameterToArray($params);
    }
1201524
public function getParent($class)
    {
        $classId = $this->getClassId($class);
        if (!isset($classId)) {
            return false;
        }
        $parentClassId = $this->extends[$classId];
        return isset($parentClassId) ? $this->classes[$parentClassId[0]] : null;
    }
1244260
public static function getClassAnnotations($class)
    {
        $annotationBag = Bridge\Loader::getInstance()->getClassAnnotations($class);
        $annotationBag = self::explodeNamespaces($annotationBag);

        return new ConfigObject($annotationBag);
    }
636246
public function getTraits(string $class){
        if(!class_exists($class)){
            throw new \InvalidArgumentException();
        }

        if(!array_key_exists($class, $this->traits)){
            $traits     = array_map(
                function($v){
                    return false;
                },
                array_flip(class_uses($class))
            );

            do{
                $continue   = false;
                $new        = [];

                foreach($traits as $trait => $flag){
                    if($flag === false){
                        $traits[$trait] = true;

                        foreach(class_uses($trait) as $use){
                            if(!array_key_exists($use, $traits)){
                                $continue   = true;
                                $new[$use]  = false;
                            }
                        }
                    }
                }

                $traits += $new;
            }while($continue === true);

            $this->traits[$class]   = array_keys($traits);
        }

        return $this->traits[$class];
    }
1161789
private function convertClassAnnotationsToMappedSuperClassMetadata(
        array $classAnnotations,
        ReflectionClass $reflectionClass,
        Mapping\ClassMetadata $parent
    ) {
        /** @var Annotation\MappedSuperclass $mappedSuperclassAnnot */
        $mappedSuperclassAnnot = $classAnnotations[Annotation\MappedSuperclass::class];
        $classMetadata         = new Mapping\MappedSuperClassMetadata($reflectionClass->getName(), $parent);

        if ($mappedSuperclassAnnot->repositoryClass !== null) {
            $classMetadata->setCustomRepositoryClassName($mappedSuperclassAnnot->repositoryClass);
        }

        return $classMetadata;
    }
717370
protected function getClassFilesetAnnotations($class) {
    $filesets = [];
    $methods = get_class_methods($class);
    foreach ($methods as $method_name) {
      $reflectionMethod = new \ReflectionMethod($class, $method_name);
      $annotations = $this->annotationsReader->getMethodAnnotation($reflectionMethod, 'Acquia\Blt\Annotations\Fileset');
      if ($annotations) {
        $filesets[$annotations->id] = $method_name;
      }
    }

    return $filesets;
  }
966331
public function getValidations($class = null)
    {
        $reflectionClass = $class ? new \ReflectionClass($class) : false;
        if ($reflectionClass === false) {
            return [];
        }
        $result = $this->buildValidation($class);
        $validations = [];
        foreach ($result as $keyElement => $element) {
            if (is_array($element)) {
                foreach ($element as $keyChild => $child) {
                    if (is_array($child)) {
                        foreach ($child as $grandChild) {
                            $validations[] = sprintf('%s => %s', $keyChild, $grandChild);
                        }
                    } else {
                        $validations[] = sprintf('%s => %s', $keyElement, $child);
                    }
                }
            } else {
                $validations[] = $element;
            }
        }

        return $validations;
    }