Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Infrastructure\Composer;
  4.  
  5. use Composer\Installer\InstallationManager;
  6. use Composer\Package\CompletePackage;
  7. use Composer\Repository\InstalledFilesystemRepository;
  8. use Composer\Script\Event;
  9. use Composer\Util\Filesystem as ComposerFilesystem;
  10. use Symfony\Component\Filesystem\Filesystem;
  11.  
  12. abstract class PathRepositoryScript
  13. {
  14. public static function resolvePath(Event $event)
  15. {
  16. $composer = $event->getComposer();
  17.  
  18. /** @var InstalledFilesystemRepository $local */
  19. $local = $composer->getRepositoryManager()->getLocalRepository();
  20. /** @var InstallationManager $installer */
  21. $installer = $composer->getInstallationManager();
  22.  
  23. $pathPackages = [];
  24. foreach ($local->getPackages() as $package) {
  25. if ('path' === $package->getDistType()) {
  26. $pathPackages[] = $package;
  27. }
  28. }
  29.  
  30. $fs = new Filesystem();
  31. $fsUtils = new ComposerFilesystem();
  32.  
  33. /** @var CompletePackage $package */
  34. foreach ($pathPackages as $package) {
  35. $packagePath = realpath($package->getDistUrl());
  36.  
  37. if (false === $packagePath || !is_dir($packagePath)) {
  38. throw new \RuntimeException(sprintf(
  39. 'Path "%s" is not found',
  40. $packagePath
  41. ));
  42. }
  43.  
  44. $installationPath = $installer->getInstallPath($package);
  45.  
  46. $fsUtils->removeDirectory($installationPath);
  47.  
  48. if ($event->isDevMode()) {
  49. $shortestPath = $fsUtils->findShortestPath($installationPath, $packagePath);
  50. $fs->symlink($shortestPath, $installationPath);
  51.  
  52. $event->getIO()->write(
  53. sprintf(' Symlinked package: %s', $package->getName()),
  54. true
  55. );
  56. } else {
  57. $fs->mirror($packagePath, $installationPath);
  58.  
  59. $event->getIO()->write(
  60. sprintf(' Mirrored package: %s', $package->getName()),
  61. true
  62. );
  63. }
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement