get use traits deep

@param   string  $class
@return  array
500456
public function class_uses_deep($class)
    {
        $traits = [];
        do {
            $traits = array_merge($traits, class_uses($class, false));
        } while ($class = get_parent_class($class));
        foreach ($traits as $trait) {
            $traits = array_merge($traits, class_uses($trait, false));
        }
        return array_unique($traits);
    }
440786
protected static function get_arguments($class)
    {
        if (isset(self::$arguments[$class])) {
            return self::$arguments[$class];
        } else {
            if ($staticFields = Config::inst()->get($class, 'translatable_fields', Config::FIRST_SET)) {
                if (is_array($staticFields) && !empty($staticFields)) {
                    return $staticFields;
                }
            }
        }

        return null;
    }
1124919
public static function getAllChildClasses($class): array
    {
        $type = gettype($class);
        $className = '';

        /* If input an object */
        if ($type == 'object') {
            $className = get_class($class);
        }

        /* If input a string */
        elseif ($type == 'string') {
            $className = $class;
        }

        $classes = [];

        /* Go through all classes */
        foreach (get_declared_classes() as $class) {
            if (is_subclass_of($class, $className)) {
                $classes[] = $class;
            }
        }

        return $classes;
    }
298186
public function getTraitsOfClass($class)
    {
        $definitions = [];

        // in case there is a hierarchy of classes
        $classes = $this->getSuperClasses($class);
        if (is_array($classes)) {
            foreach ($classes as $subClass) {
                if (isset($subClass['traits'])) {
                    foreach ($subClass['traits'] as $classTrait) {
                        foreach ($this->traits as $trait) {
                            if ($classTrait === $trait['trait']) {
                                $traitDefinition[$trait['trait']] = $trait;
                                $definitions = array_merge($definitions, $traitDefinition);
                            }
                        }
                    }
                }
            }
        }

        // trait used by the given class
        $classDefinition = isset($this->classes[$class]) ? $this->classes[$class] : null;
        if (!$classDefinition || empty($classDefinition['traits'])) {
            return $definitions;
        }
        $classTraits = $classDefinition['traits'];
        foreach ($this->traits as $trait) {
            foreach ($classTraits as $classTrait => $name) {
                if ($trait['trait'] === $name) {
                    $traitDefinition[$name] = $trait;
                    $definitions = array_merge($definitions, $traitDefinition);
                }
            }
        }

        return $definitions;
    }
509027
public static function getClassMethods($context, $class) {
        $methods = array();

        foreach ($class->getMethods() as $method) {
            $meta = static::getMeta($method);
            $methods[$meta['name']] = static::scanDependency($context, preg_replace('/public static function (.+)\\(/', "function {$context['funcprefix']}\$1(", $meta['code']), $meta['code']);
        }

        return $methods;
    }
714650
protected function getDependencies($class)
    {
        if (isset($this->_reflections[$class])) {
            return [$this->_reflections[$class], $this->_dependencies[$class]];
        }

        $dependencies = [];
        $reflection = new ReflectionClass($class);

        $constructor = $reflection->getConstructor();
        if ($constructor !== null) {
            foreach ($constructor->getParameters() as $param) {
                if ($param->isDefaultValueAvailable()) {
                    $dependencies[] = $param->getDefaultValue();
                } else {
                    $c = $param->getClass();
                    $dependencies[] = Instance::of($c === null ? null : $c->getName());
                }
            }
        }

        $this->_reflections[$class] = $reflection;
        $this->_dependencies[$class] = $dependencies;

        return [$reflection, $dependencies];
    }
812291
public static function getTraits($class, bool $autoload = true): array
	{
		// Fetch all traits used by a class and its parents

		$traits = [];

		do
		{
			$traits += class_uses($class, $autoload);
		}
		while($class = get_parent_class($class));

		// Find all traits used by the traits

		$search = $traits;

		$searched = [];

		while(!empty($search))
		{
			$trait = array_pop($search);

			if(isset($searched[$trait]))
			{
				continue;
			}

			$traits += $search += class_uses($trait, $autoload);

			$searched[$trait] = $trait;
		}

		// Return complete list of traits used by the class

		return $traits;
	}
744079
private static function getProperties($class): array
    {
        $reflect = new \ReflectionClass($class);
        $prop = $reflect->getProperties(
            \ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED | \ReflectionProperty::IS_PRIVATE
        );
        $properties = [];
        foreach ($prop as $property) {
            $properties[] = $property->name;
        }
        $parent = \get_parent_class($class);
        if ($parent) {
            $properties = \array_merge(self::getProperties($parent), $properties);
        }
        return $properties;
    }
1200656
public function toClass($class)
    {
        if (count($this->traitReflections) == 0) {
            throw new BadMethodCallException("No traits to add were found. Call 'addTrait' first.");
        }

        $classReflection = new ReflectionClass($class);

        $filePath = $classReflection->getFileName();

        $content = file($filePath);

        foreach ($this->traitReflections as $traitReflection) {
            $handler = new AbstractTreeHandler(
                $content,
                $traitReflection->getName(),
                $classReflection->getName()
            );

            $content = $handler->handle()->toArray();
        }

        file_put_contents($filePath, implode($content));

        return $this;
    }
916214
private function getEntityTypeInfo($class)
    {
        $entityType = $this->getEntityType($class);

        if (!$entityType) {
            return [null, null];
        }

        $info = entity_get_info($entityType);

        if (!$info) {
            return [null, null];
        }

        return [$entityType, $info];
    }
282101
public function findExtends($class) {
        $this->init();

        $fullQualifiedNamespace = $this->trimNamespace($class);

        $phpClasses = [];

        foreach ($this->localCache as $phpClass) {
            if ($fullQualifiedNamespace === $phpClass->getExtends()) {
                $phpClasses[] = $phpClass;
                $phpClasses   = array_merge($phpClasses, $this->findExtends($phpClass->getFullQualifiedNamespace()));
            }
        }

        return $this->arrayUniqueObject($phpClasses);
    }
160642
private function getAllUseStatementsMarkedAsAnnotation(\ReflectionClass $class): array
    {
        $tokens = \token_get_all(\file_get_contents($class->getFileName()));

        $uses = [];
        $buffer = '';
        $startUseParse = false;

        foreach ($tokens as $token) {
            if (\is_scalar($token)) {
                // Single element
                if ($token == ';' || $token = ',') {
                    if ($startUseParse) {
                        // Add "use" statement to collection
                        $uses[] = trim($buffer);
                        // Clear buffer
                        $buffer = ''; // Clear buffer

                        if ($token == ';') {
                            // Stop parse "use"
                            $startUseParse = false;
                        }
                    }
                }

                continue;
            }

            $type = $token[0];
            $value = $token[1];

            if (\in_array($type, [T_ABSTRACT, T_CLASS, T_INTERFACE, T_TRAIT])) {
                // Start class or interface or trait
                break;
            }

            if ($type == T_USE) {
                $startUseParse = true;
                continue;
            }

            if ($startUseParse) {
                $buffer .= $value;
            }
        }

        $useFiltering = function ($class, $searchChild = true) use (&$useFiltering) {
            if (!$class) {
                return false;
            }

            $parts = \explode(' as ', $class, 2);
            $class = $parts[0];

            try {
                $reflection = new \ReflectionClass($class);
            } catch (\ReflectionException $e) {
                if ($searchChild) {
                    foreach (\get_declared_classes() as $declaredClass) {
                        if (\strpos($declaredClass, $class) === 0) {
                            if (true === $useFiltering($declaredClass, false)) {
                                return true;
                            }
                        }
                    }
                }

                return false;
            }

            if ($reflection->getName() == Transactional::class) {
                return false;
            }

            return \strpos($reflection->getDocComment(), '@Annotation') !== false;
        };

        $uses = \array_filter($uses, $useFiltering);

        return $uses;
    }
1103758
public static function getSelectFields($class)
    {
        $select = [$class::getRoleFieldStatic('id'),];
        if ($parentLinkedField = $class::getRoleFieldStatic('tree-parent')) {
            $select[] = $parentLinkedField;
        }
        $select[] = $class::getRoleFieldStatic('sort-index');
        return $select;
    }
874063
protected function getDefineDatas($class)
    {
        $class = is_string($class) ? $class : get_class($class);
        $id = $this->request->has('parent') && $this->request->parent != 0 ? $this->request->parent : $this->request->related;
        $parent = $class::findOrFail($id);
        $datas = $this->request->all();
        foreach($this->defineValues as $value) {
            $datas[$value] = $parent->$value;
        }
        return $datas;
    }
820883
public function getEntityRepositories($class)
    {
        $identifiers = $this->getEntityIdentifiers($class);

        foreach ($identifiers as $i => $identifier) {
            $identifiers[$i] = AnDomain::getRepository($identifier);
        }

        return $identifiers;
    }
243697
public function getSubClasses($class)
    {
        $class = $this->normalize($class);
        if ($this->classExists($class)) {
            return $this->getSubclassOfClass($class);
        } elseif ($this->interfaceExists($class)) {
            return $this->getSubclassOfInterface($class);
        } else {
            throw new ClassNotExistException($class);
        }
    }
781640
public function getClassProperties($class)
    {
        $result = '';
        foreach($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property)
        {
            $static = $property->isStatic() ? ' static' : '';
            $name = $property->name;
            $result .= <<<CODE
    public{$static} \${$name};

CODE;
        }
        return $result;
    }