function GenerateAutoloadReferenceFile::generateAutoload

Same name in other branches
  1. 9 composer/Plugin/Scaffold/GenerateAutoloadReferenceFile.php \Drupal\Composer\Plugin\Scaffold\GenerateAutoloadReferenceFile::generateAutoload()
  2. 8.9.x composer/Plugin/Scaffold/GenerateAutoloadReferenceFile.php \Drupal\Composer\Plugin\Scaffold\GenerateAutoloadReferenceFile::generateAutoload()
  3. 11.x composer/Plugin/Scaffold/GenerateAutoloadReferenceFile.php \Drupal\Composer\Plugin\Scaffold\GenerateAutoloadReferenceFile::generateAutoload()

Generates the autoload file at the specified location.

This only writes a bit of PHP that includes the autoload file that Composer generated. Drupal does this so that it can guarantee that there will always be an `autoload.php` file in a well-known location.

Parameters

\Composer\IO\IOInterface $io: IOInterface to write to.

string $package_name: The name of the package defining the autoload file (the root package).

string $web_root: The path to the web root.

string $vendor: The path to the vendor directory.

Return value

\Drupal\Composer\Plugin\Scaffold\Operations\ScaffoldResult The result of the autoload file generation.

1 call to GenerateAutoloadReferenceFile::generateAutoload()
Handler::scaffold in composer/Plugin/Scaffold/Handler.php
Copies all scaffold files from source to destination.

File

composer/Plugin/Scaffold/GenerateAutoloadReferenceFile.php, line 41

Class

GenerateAutoloadReferenceFile
Generates an 'autoload.php' that includes the autoloader created by Composer.

Namespace

Drupal\Composer\Plugin\Scaffold

Code

public static function generateAutoload(IOInterface $io, $package_name, $web_root, $vendor) {
    $autoload_path = static::autoloadPath($package_name, $web_root);
    // Calculate the relative path from the webroot (location of the project
    // autoload.php) to the vendor directory.
    $fs = new Filesystem();
    $relative_autoload_path = $fs->findShortestPath($autoload_path->fullPath(), "{$vendor}/autoload.php");
    file_put_contents($autoload_path->fullPath(), static::autoLoadContents($relative_autoload_path));
    return new ScaffoldResult($autoload_path, TRUE);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.