2 namespace TYPO3\CMS\Composer\Plugin\Core;
34 $this->filesystem = $this->filesystem ?: new \TYPO3\CMS\Composer\Plugin\Util\Filesystem();
41 $composer = $event->getComposer();
42 $composerConfig = $composer->getConfig();
43 $localRepository = $composer->getRepositoryManager()->getLocalRepository();
45 foreach ($localRepository->getCanonicalPackages() as $package) {
46 if ($package->getType() ===
'typo3-cms-core') {
47 $defaultVendorDir = \Composer\Config::$defaultConfig[
'vendor-dir'];
49 $packagePath = $composer->getInstallationManager()->getInstallPath($package);
50 $jsonFile = new \Composer\Json\JsonFile($packagePath . DIRECTORY_SEPARATOR .
'composer.json',
new \Composer\Util\RemoteFilesystem($event->getIO()));
51 $packageJson = $jsonFile->read();
52 $packageVendorDir = !empty($packageJson[
'config'][
'vendor-dir']) ? $this->filesystem->normalizePath($packageJson[
'config'][
'vendor-dir']) : $defaultVendorDir;
54 $autoloaderSourceDir = $composerConfig->get(
'vendor-dir');
55 $autoloaderTargetDir = $packagePath . DIRECTORY_SEPARATOR . $packageVendorDir;
56 $autoloaderFileName =
'autoload.php';
58 $this->filesystem->ensureDirectoryExists($autoloaderTargetDir);
59 $this->filesystem->remove($autoloaderTargetDir . DIRECTORY_SEPARATOR . $autoloaderFileName);
61 $this->filesystem->symlink(
62 $autoloaderSourceDir . DIRECTORY_SEPARATOR . $autoloaderFileName,
63 $autoloaderTargetDir . DIRECTORY_SEPARATOR . $autoloaderFileName,
66 }
catch (\RuntimeException $e) {
67 if ($e->getCode() !== 1430494084) {
72 'return require ' . $this->filesystem->findShortestPathCode(
73 $autoloaderTargetDir . DIRECTORY_SEPARATOR . $autoloaderFileName,
74 $autoloaderSourceDir . DIRECTORY_SEPARATOR . $autoloaderFileName
77 file_put_contents($autoloaderTargetDir . DIRECTORY_SEPARATOR . $autoloaderFileName, implode(chr(10), $code));
89 $composer = $event->getComposer();
91 if (!$pluginConfig->get(
'composer-mode')) {
94 $composerConfig = $composer->getConfig();
95 $vendorDir = $composerConfig->get(
'vendor-dir');
97 $io = $event->getIO();
98 if (!file_exists($autoloadFile)) {
99 throw new \RuntimeException(sprintf(
100 'Could not adjust autoloader: The file %s was not found.',
105 $io->write(
'<info>Inserting TYPO3_COMPOSER_MODE constant</info>');
107 $contents = file_get_contents($autoloadFile);
108 $constant =
"if (!defined('TYPO3_COMPOSER_MODE')) {\n";
109 $constant .=
" define('TYPO3_COMPOSER_MODE', TRUE);\n";
110 $constant .=
"}\n\n";
116 $contents = preg_replace(
'/\n(?=return [^;]+;\s*$)/mD',
"\n" . $constant, $contents);
117 file_put_contents($autoloadFile, $contents);