findShortestPath($autoload_path->fullPath(), "$vendor/autoload.php"); file_put_contents($autoload_path->fullPath(), static::autoLoadContents($relative_autoload_path)); return new ScaffoldResult($autoload_path, TRUE); } /** * Determines whether or not the autoload file has been committed. * * @param \Composer\IO\IOInterface $io * IOInterface to write to. * @param string $package_name * The name of the package defining the autoload file (the root package). * @param string $web_root * The path to the web root. * * @return bool * True if autoload.php file exists and has been committed to the repository */ public static function autoloadFileCommitted(IOInterface $io, $package_name, $web_root) { $autoload_path = static::autoloadPath($package_name, $web_root); $autoload_file = $autoload_path->fullPath(); $location = dirname($autoload_file); if (!file_exists($autoload_file)) { return FALSE; } return Git::checkTracked($io, $autoload_file, $location); } /** * Generates a scaffold file path object for the autoload file. * * @param string $package_name * The name of the package defining the autoload file (the root package). * @param string $web_root * The path to the web root. * * @return \Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath * Object wrapping the relative and absolute path to the destination file. */ protected static function autoloadPath($package_name, $web_root) { $rel_path = 'autoload.php'; $dest_rel_path = '[web-root]/' . $rel_path; $dest_full_path = $web_root . '/' . $rel_path; return new ScaffoldFilePath('autoload', $package_name, $dest_rel_path, $dest_full_path); } /** * Builds the contents of the autoload file. * * @param string $relative_autoload_path * The relative path to the autoloader in vendor. * * @return string * Return the contents for the autoload.php. */ protected static function autoLoadContents($relative_autoload_path) { $relative_autoload_path = preg_replace('#^\./#', '', $relative_autoload_path); return <<