source = $source; $this->target = $target; } public function run(Event $event): bool { $composer = $event->getComposer(); $filesystemUtility = new FilesystemUtility(); $filesystem = new Filesystem(); $pluginConfig = Config::load($composer); $entryPointContent = file_get_contents($this->source); if ($entryPointContent === false) { return false; } $targetFile = $pluginConfig->get('root-dir') . '/' . $this->target; $autoloadFile = $composer->getConfig()->get('vendor-dir') . '/autoload.php'; $entryPointContent = preg_replace( '/__DIR__ . \'[^\']*\'/', $filesystemUtility->findShortestPathCode($targetFile, $autoloadFile), $entryPointContent ); $filesystemUtility->ensureDirectoryExists(dirname($targetFile)); $filesystem->dumpFile($targetFile, $entryPointContent); $filesystem->chmod($targetFile, 0755); return $filesystem->exists($targetFile); } }