public static function savePsr4s($vendorDir, $localPsr4Config, $io) { $filesystem = new FileSystem(); $psr4File = $filesystem->normalizePath(realpath($vendorDir . self::PSR4_FILE)); if ($localPsr4Config && $psr4File) { $io->write('generating local autoload_psr4.php ....'); self::appendBeforeLastline($localPsr4Config, $psr4File); $io->write('local autoload_psr4 generated.'); } }
/** * Generates fake autoload file pointing to real autoload.php * * @param BasePackage packager * @param string target file path */ protected function generateFakeAutoloadFile(BasePackage $package, $targetPath) { // Prepare paths $packageInstallPath = $this->getInstallPath($package); $targetDir = $this->fs->normalizePath($packageInstallPath . '/' . dirname($targetPath)); $targetBasename = basename($targetPath); // Create short path to fake autoload file (for display purposes) $displayFilePath = $this->fs->findShortestPath($this->getBasePath(), "{$targetDir}/{$targetBasename}"); // If target directory does not exist, skip if (!is_dir($targetDir)) { $this->io->write('Skiping generation of fake autoload file: ' . $displayFilePath); return; } // Find relative path from directory of fake autoload file to real autoload.php $relativePath = $this->fs->findShortestPath($targetDir, $this->getVendorDirPath(), TRUE); $autoloadPath = var_export('/' . rtrim($relativePath, '/') . '/autoload.php', TRUE); // Create fake autoload content $content = <<<BOOTSTRAP_END <?php /** * @warning This file is automatically generated by Composer. * @see https://github.com/vbuilder/composer-plugin */ return include __DIR__ . {$autoloadPath}; BOOTSTRAP_END; // Write $this->io->write('Generating fake autoload in: ' . $displayFilePath); file_put_contents($targetDir . '/' . $targetBasename, $content); // Mark file as unchanged for Git if (is_dir("{$packageInstallPath}/.git")) { $exitCode = $this->process->execute('git --git-dir ' . escapeshellarg("{$packageInstallPath}/.git") . ' --work-tree ' . escapeshellarg($packageInstallPath) . ' update-index --assume-unchanged ' . escapeshellarg($targetPath)); if ($exitCode) { throw new \RuntimeException('Failed to mark ' . $displayFilePath . ' as unchanged'); } } }