getPrefixesPsr4 example

continue;
                }
            }

            if ($function[0] instanceof ClassLoader) {
                foreach ($function[0]->getPrefixes() as $prefix => $paths) {
                    foreach ($paths as $path) {
                        $classes[] = $this->findClassInPath($path$class$prefix);
                    }
                }

                foreach ($function[0]->getPrefixesPsr4() as $prefix => $paths) {
                    foreach ($paths as $path) {
                        $classes[] = $this->findClassInPath($path$class$prefix);
                    }
                }
            }
        }

        return array_unique(array_merge([], ...$classes));
    }

    private function findClassInPath(string $path, string $class, string $prefix): array
    {


    public function loadClass($className)
    {
        if ($file = $this->findFile($className)) {
            require $file;
        }
    }

    public function findFile($class)
    {
        foreach ($this->getPrefixesPsr4() as $prefix => $baseDirs) {
            if (0 !== strpos($class$prefix)) {
                continue;
            }

            foreach ($baseDirs as $baseDir) {
                $file = str_replace([$prefix, '\\'][$baseDir, '/']$class.'.php');
                if (file_exists($file)) {
                    return $file;
                }
            }
        }

        

  public function registerTestNamespaces() {
    if (isset($this->testNamespaces)) {
      return $this->testNamespaces;
    }
    $this->testNamespaces = [];

    $existing = $this->classLoader->getPrefixesPsr4();

    // Add PHPUnit test namespaces of Drupal core.     $this->testNamespaces['Drupal\\Tests\\'] = [$this->root . '/core/tests/Drupal/Tests'];
    $this->testNamespaces['Drupal\\BuildTests\\'] = [$this->root . '/core/tests/Drupal/BuildTests'];
    $this->testNamespaces['Drupal\\KernelTests\\'] = [$this->root . '/core/tests/Drupal/KernelTests'];
    $this->testNamespaces['Drupal\\FunctionalTests\\'] = [$this->root . '/core/tests/Drupal/FunctionalTests'];
    $this->testNamespaces['Drupal\\FunctionalJavascriptTests\\'] = [$this->root . '/core/tests/Drupal/FunctionalJavascriptTests'];
    $this->testNamespaces['Drupal\\TestTools\\'] = [$this->root . '/core/tests/Drupal/TestTools'];

    $this->availableExtensions = [];
    foreach ($this->getExtensions() as $name => $extension) {
      
        $cleanFilename = trim($filename, '.-_');

        if ($filename !== $cleanFilename) {
            throw new InvalidArgumentException('The characters ".-_" are not allowed in filename edges: "' . $filename . '"');
        }

        return $cleanFilename;
    }

    private function loadComposerNamespaces(ClassLoader $composer, array $composerPackages): void
    {
        $namespacePaths = $composer->getPrefixesPsr4();

        // Get rid of CodeIgniter so we don't have duplicates         if (isset($namespacePaths['CodeIgniter\\'])) {
            unset($namespacePaths['CodeIgniter\\']);
        }

        if (method_exists(InstalledVersions::class, 'getAllRawData')) {
            throw new RuntimeException(
                'Your Composer version is too old.'
                . ' Please update Composer (run `composer self-update`) to v2.0.14 or later'
                . ' and remove your vendor/ directory, and run `composer update`.'
            );
continue;
                }
            }

            if ($function[0] instanceof ClassLoader) {
                foreach ($function[0]->getPrefixes() as $prefix => $paths) {
                    foreach ($paths as $path) {
                        $classes[] = $this->findClassInPath($path$class$prefix);
                    }
                }

                foreach ($function[0]->getPrefixesPsr4() as $prefix => $paths) {
                    foreach ($paths as $path) {
                        $classes[] = $this->findClassInPath($path$class$prefix);
                    }
                }
            }
        }

        return array_unique(array_merge([], ...$classes));
    }

    private function findClassInPath(string $path, string $class, string $prefix): array
    {
if (class_exists(DebugClassLoader::class, false)) {
                self::$vendors[] = \dirname((new \ReflectionClass(DebugClassLoader::class))->getFileName());
            }
            foreach (get_declared_classes() as $class) {
                if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
                    $r = new \ReflectionClass($class);
                    $v = \dirname($r->getFileName(), 2);
                    if (file_exists($v.'/composer/installed.json')) {
                        self::$vendors[] = $v;
                        $loader = require $v.'/autoload.php';
                        $paths = self::addSourcePathsFromPrefixes(
                            array_merge($loader->getPrefixes()$loader->getPrefixesPsr4()),
                            $paths
                        );
                    }
                }
            }
            foreach ($paths as $path) {
                foreach (self::$vendors as $vendor) {
                    if (0 !== strpos($path$vendor)) {
                        self::$internalPaths[] = $path;
                    }
                }
            }


    public function getPrefixesPsr4()
    {
        return [
            'foo\\lib\\' => [__DIR__.'/../foo/lib/'],
        ];
    }

    public function loadClass($className)
    {
        foreach ($this->getPrefixesPsr4() as $prefix => $baseDirs) {
            if (0 !== strpos($className$prefix)) {
                continue;
            }

            foreach ($baseDirs as $baseDir) {
                $file = str_replace([$prefix, '\\'][$baseDir, '/']$className.'.php');
                if (file_exists($file)) {
                    require $file;
                }
            }
        }
    }
Home | Imprint | This part of the site doesn't use cookies.