extractFromFullClassName example


final class NameScopeFactory
{
    public function create(string $calledClassName, string $declaringClassName = null): NameScope
    {
        $declaringClassName ??= $calledClassName;

        $path = explode('\\', $calledClassName);
        $calledClassName = array_pop($path);

        $declaringReflection = new \ReflectionClass($declaringClassName);
        [$declaringNamespace$declaringUses] = $this->extractFromFullClassName($declaringReflection);
        $declaringUses = array_merge($declaringUses$this->collectUses($declaringReflection));

        return new NameScope($calledClassName$declaringNamespace$declaringUses);
    }

    private function collectUses(\ReflectionClass $reflection): array
    {
        $uses = [$this->extractFromFullClassName($reflection)[1]];

        foreach ($reflection->getTraits() as $traitReflection) {
            $uses[] = $this->extractFromFullClassName($traitReflection)[1];
        }
Home | Imprint | This part of the site doesn't use cookies.