Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. LinkStub.php

function LinkStub::getComposerRoot

1 call to LinkStub::getComposerRoot()
LinkStub::__construct in vendor/symfony/var-dumper/Caster/LinkStub.php

File

vendor/symfony/var-dumper/Caster/LinkStub.php, line 63

Class

LinkStub
Represents a file or a URL.

Namespace

Symfony\Component\VarDumper\Caster

Code

private function getComposerRoot(string $file, bool &$inVendor) : string|false {
    if (!isset(self::$vendorRoots)) {
        self::$vendorRoots = [];
        foreach (get_declared_classes() as $class) {
            if ('C' === $class[0] && str_starts_with($class, 'ComposerAutoloaderInit')) {
                $r = new \ReflectionClass($class);
                $v = \dirname($r->getFileName(), 2);
                if (is_file($v . '/composer/installed.json')) {
                    self::$vendorRoots[] = $v . \DIRECTORY_SEPARATOR;
                }
            }
        }
    }
    $inVendor = false;
    if (isset(self::$composerRoots[$dir = \dirname($file)])) {
        return self::$composerRoots[$dir];
    }
    foreach (self::$vendorRoots as $root) {
        if ($inVendor = str_starts_with($file, $root)) {
            return $root;
        }
    }
    $parent = $dir;
    while (!@is_file($parent . '/composer.json')) {
        if (!@file_exists($parent)) {
            // open_basedir restriction in effect
            break;
        }
        if ($parent === \dirname($parent)) {
            return self::$composerRoots[$dir] = false;
        }
        $parent = \dirname($parent);
    }
    return self::$composerRoots[$dir] = $parent . \DIRECTORY_SEPARATOR;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal