Gets a recursive list of traits used by a class

@param string $class Full class name

@return array
5
private function getRecursiveTraits($class = null)
    {
        if (null == $class) {
            $class = get_class($this);
        }

        $reflection = new \ReflectionClass($class);
        $traits = array_keys($reflection->getTraits());

        foreach ($traits as $trait) {
            $traits = array_merge($traits, $this->getRecursiveTraits($trait));
        }

        if ($parent = $reflection->getParentClass()) {
            $traits = array_merge($traits, $this->getRecursiveTraits($parent->getName()));
        }

        return $traits;
    }
810313
public function getChildrenOfClass($class)
    {
        // Check for namespace alias
        if (strpos($class, ':') !== false) {
            list($namespaceAlias, $simpleClassName) = explode(':', $class);
            $class = $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
        }
        $result = array();
        $children = $this->getChildren();
        foreach ($children as $child) {
            if ($child->getPage() instanceof $class) {
                $result[] = $child;
            }
        }

        return $result;
    }
403411
public function getTemplateForClass($class)
    {
        foreach (ClassTools::singleton()->getReverseAncestry($class) as $name) {
            
            if ($type = PageType::findByClass($name)) {
                
                if ($type->hasPageTemplate()) {
                    return $type->getPageTemplate();
                }
                
            }
            
            if ($name == SiteTree::class) {
                break;
            }
            
        }
    }
653332
public final function toClass(string $class): ?array
    {
        $data = null;
        if (!empty($this->data)) {
            $data = $this->data;
            foreach ($data as &$dat) {
                $datClass = new $class();
                foreach ((array) $dat as $key => $value) {
                    $datClass->{$key} = $value;
                }
                $dat = $datClass;
            }
        }

        return $data;
    }
103106
protected function pStmt_Class(Class_ $class): string
    {
        $shouldReindex = false;

        foreach ($class->stmts as $key => $stmt) {
            if ($stmt instanceof TraitUse) {
                // remove empty ones
                if (count($stmt->traits) === 0) {
                    unset($class->stmts[$key]);
                    $shouldReindex = true;
                }
            }
        }

        if ($shouldReindex) {
            $class->stmts = array_values($class->stmts);
        }

        return parent::pStmt_Class($class);
    }
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 [];
    }
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;
    }
1074658
private function getClassMethods($class)
    {
        $result = '';

        foreach($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method)
        {
            $args = [];
            $comments = [];
            foreach($method->getParameters() as $param)
            {
                // 方法参数定义
                $args[] = $this->getMethodParamDefine($param);
                $comments[] = '@var ' . ($param->getType() ?? 'mixed') . ' $' . $param->name;
            }
            $return = $method->getReturnType();
            if(null !== $return)
            {
                $comments[] = '@return ' . $return;
            }
            $args = implode(', ', $args);
            if([] === $comments)
            {
                $comment = '';
            }
            else
            {
                $comment = implode(PHP_EOL . '     * ', $comments);
                $comment = <<<COMMENT

    /**
     * {$comment}
     */
COMMENT;
            }
            if($method->isStatic())
            {
                $static = ' static';
            }
            else
            {
                $static = '';
            }
            $result .= <<<CODE
{$comment}
    public{$static} function {$method->name}({$args}){}

CODE;
        }

        return $result;
    }
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;
    }
1023282
public static function getClassMethodArgs($class, string $method)
    {
        static $cache = null;

        if (null !== $cache && isset($cache[$class][$method])) {
            return $cache[$class][$method];
        }

        $reflector = new \ReflectionMethod($class, $method);
        $params = $reflector->getParameters();
        if (empty($params)) {
            $cache[$class][$method] = [];
            return [];
        }
        $args = [];
        foreach ($params as $param) {
            $args[$param->name] = [
                'optional' => $param->isOptional(),
                'variadic' => $param->isVariadic(),
            ];
            if ($param->isOptional() && $param->isDefaultValueAvailable()) {
                $args[$param->name]['default'] = $param->getDefaultValue();
            }
            if ($param->hasType()) {
                $args[$param->name]['type'] = (string)$param->getType();
            }
        }
        $cache[$class][$method] = $args;
        return $args;
    }
1001969
public function getLayoutForClass($class)
    {
        foreach (ClassTools::singleton()->getReverseAncestry($class) as $name) {
            
            if ($type = PageType::findByClass($name)) {
                
                if ($type->hasPageLayout()) {
                    return $type->getPageLayout();
                }
                
            }
            
            if ($name == SiteTree::class) {
                break;
            }
            
        }
    }
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);
    }
1038970
public static function getByClass( $class )
	{
		$results = [];
		foreach ( static::$globals as $k => $v )
			if ( $v instanceof $class )
				$results[$k] = $v;
		return $results;
	}
826396
public static function cacheMutatedAttributes($class)
    {
        $mutatedAttributes = [];
        // Here we will extract all of the mutated attributes so that we can quickly
        // spin through them after we export models to their array form, which we
        // need to be fast. This'll let us know the attributes that can mutate.
        foreach (get_class_methods($class) as $method) {
            if (strpos($method, 'Attribute') !== false &&
                preg_match('/^get(.+)Attribute$/', $method, $matches)
            ) {
                if (static::$snakeAttributes) {
                    $matches[1] = Helper::snake($matches[1]);
                }
                $mutatedAttributes[] = lcfirst($matches[1]);
            }
        }
        static::$mutatorCache[$class] = $mutatedAttributes;
    }
1300925
private static function getMethods($methods, $class): array
    {
        $methods[] = \array_fill_keys(\get_class_methods($class), 0);
        $parent = \get_parent_class($class);
        if ($parent) {
            \array_merge($methods, self::getMethods($methods, $parent));
        }
        return $methods[0];
    }
200357
protected function getMappableFieldsForClass($class)
    {
        $singleton = singleton($class);
        $fields = (array)$singleton->fieldLabels(false);
        foreach ($fields as $field => $label) {
            if (!$singleton->hasField($field)) {
                unset($fields[$field]);
            }
        }
        return $fields;
    }
91123
public function findByClass($className)
    {
        $result = [];
        foreach ($this->_traits as $trait) {
            if ($trait->matchClassName($className)) {
                $result[] = $trait;
            }
        }
        $result = SortUtils::sortReflections($result);

        return $result;
    }