Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Infrastructure\Composer;
- use Composer\Installer\InstallationManager;
- use Composer\Package\CompletePackage;
- use Composer\Repository\InstalledFilesystemRepository;
- use Composer\Script\Event;
- use Composer\Util\Filesystem as ComposerFilesystem;
- use Symfony\Component\Filesystem\Filesystem;
- abstract class PathRepositoryScript
- {
- public static function resolvePath(Event $event)
- {
- $composer = $event->getComposer();
- /** @var InstalledFilesystemRepository $local */
- $local = $composer->getRepositoryManager()->getLocalRepository();
- /** @var InstallationManager $installer */
- $installer = $composer->getInstallationManager();
- $pathPackages = [];
- foreach ($local->getPackages() as $package) {
- if ('path' === $package->getDistType()) {
- $pathPackages[] = $package;
- }
- }
- $fs = new Filesystem();
- $fsUtils = new ComposerFilesystem();
- /** @var CompletePackage $package */
- foreach ($pathPackages as $package) {
- $packagePath = realpath($package->getDistUrl());
- if (false === $packagePath || !is_dir($packagePath)) {
- throw new \RuntimeException(sprintf(
- 'Path "%s" is not found',
- $packagePath
- ));
- }
- $installationPath = $installer->getInstallPath($package);
- $fsUtils->removeDirectory($installationPath);
- if ($event->isDevMode()) {
- $shortestPath = $fsUtils->findShortestPath($installationPath, $packagePath);
- $fs->symlink($shortestPath, $installationPath);
- $event->getIO()->write(
- sprintf(' Symlinked package: %s', $package->getName()),
- true
- );
- } else {
- $fs->mirror($packagePath, $installationPath);
- $event->getIO()->write(
- sprintf(' Mirrored package: %s', $package->getName()),
- true
- );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement