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

Breadcrumb

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

function AutoloadGenerator::getStaticFile

Parameters

string $vendorPath input for findShortestPathCode:

string $basePath input for findShortestPathCode:

Return value

string

1 call to AutoloadGenerator::getStaticFile()
AutoloadGenerator::dump in vendor/composer/composer/src/Composer/Autoload/AutoloadGenerator.php

File

vendor/composer/composer/src/Composer/Autoload/AutoloadGenerator.php, line 1129

Class

AutoloadGenerator
@author Igor Wiedler <igor@wiedler.ch> @author Jordi Boggiano <j.boggiano@seld.be>

Namespace

Composer\Autoload

Code

protected function getStaticFile(string $suffix, string $targetDir, string $vendorPath, string $basePath) {
    $file = <<<HEADER
<?php

// autoload_static.php @generated by Composer

namespace Composer\\Autoload;

class ComposerStaticInit{<span class="php-variable">$suffix</span>}
{

HEADER;
    $loader = new ClassLoader();
    $map = (require $targetDir . '/autoload_namespaces.php');
    foreach ($map as $namespace => $path) {
        $loader->set($namespace, $path);
    }
    $map = (require $targetDir . '/autoload_psr4.php');
    foreach ($map as $namespace => $path) {
        $loader->setPsr4($namespace, $path);
    }
    
    /**
     * @var string $vendorDir
     * @var string $baseDir
     */
    $classMap = (require $targetDir . '/autoload_classmap.php');
    if ($classMap) {
        $loader->addClassMap($classMap);
    }
    $filesystem = new Filesystem();
    $vendorPathCode = ' => ' . $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true, true) . " . '/";
    $vendorPharPathCode = ' => \'phar://\' . ' . $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true, true) . " . '/";
    $appBaseDirCode = ' => ' . $filesystem->findShortestPathCode(realpath($targetDir), $basePath, true, true) . " . '/";
    $appBaseDirPharCode = ' => \'phar://\' . ' . $filesystem->findShortestPathCode(realpath($targetDir), $basePath, true, true) . " . '/";
    $absoluteVendorPathCode = ' => ' . substr(var_export(rtrim($vendorDir, '\\/') . '/', true), 0, -1);
    $absoluteVendorPharPathCode = ' => ' . substr(var_export(rtrim('phar://' . $vendorDir, '\\/') . '/', true), 0, -1);
    $absoluteAppBaseDirCode = ' => ' . substr(var_export(rtrim($baseDir, '\\/') . '/', true), 0, -1);
    $absoluteAppBaseDirPharCode = ' => ' . substr(var_export(rtrim('phar://' . $baseDir, '\\/') . '/', true), 0, -1);
    $initializer = '';
    $prefix = "\x00Composer\\Autoload\\ClassLoader\x00";
    $prefixLen = strlen($prefix);
    if (file_exists($targetDir . '/autoload_files.php')) {
        $maps = [
            'files' => require $targetDir . '/autoload_files.php',
        ];
    }
    else {
        $maps = [];
    }
    foreach ((array) $loader as $prop => $value) {
        if (!is_array($value) || \count($value) === 0 || !str_starts_with($prop, $prefix)) {
            continue;
        }
        $maps[substr($prop, $prefixLen)] = $value;
    }
    foreach ($maps as $prop => $value) {
        $value = strtr(var_export($value, true), [
            $absoluteVendorPathCode => $vendorPathCode,
            $absoluteVendorPharPathCode => $vendorPharPathCode,
            $absoluteAppBaseDirCode => $appBaseDirCode,
            $absoluteAppBaseDirPharCode => $appBaseDirPharCode,
        ]);
        $value = ltrim(Preg::replace('/^ */m', '    $0$0', $value));
        $file .= sprintf("    public static \$%s = %s;\n\n", $prop, $value);
        if ('files' !== $prop) {
            $initializer .= "            \$loader->{$prop} = ComposerStaticInit{$suffix}::\${$prop};\n";
        }
    }
    return $file . <<<INITIALIZER
    public static function getInitializer(ClassLoader \$loader)
    {
        return \\Closure::bind(function () use (\$loader) {
{<span class="php-variable">$initializer</span>}
        }, null, ClassLoader::class);
    }
}

INITIALIZER;
}

API Navigation

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