/** * @param string $packageName * @param string $sourceDirectory * @param string $targetDirectory */ protected static function mirrorDirectory($packageName, $sourceDirectory, $targetDirectory) { $packages = static::$localRepository->findPackages($packageName, null); foreach ($packages as $package) { if (static::$installationManager->getInstaller($package->getType())->isInstalled(static::$localRepository, $package)) { static::getFileSystem()->mirror(static::$installationManager->getInstallPath($package) . '/' . ltrim($sourceDirectory, '/'), $targetDirectory, null, ['copy_on_windows']); return; } } }
public function testAddGetInstaller() { $installer = $this->createInstallerMock(); $installer->expects($this->exactly(2))->method('supports')->will($this->returnCallback(function ($arg) { return $arg === 'vendor'; })); $manager = new InstallationManager('vendor'); $manager->addInstaller($installer); $this->assertSame($installer, $manager->getInstaller('vendor')); $this->setExpectedException('InvalidArgumentException'); $manager->getInstaller('unregistered'); }
public function mapContrib(InstallationManager $im, RepositoryManager $rm) { $typePathMap = $this->getTypePathMap(); $typeInstallMap = []; $packages = $rm->getLocalRepository()->getCanonicalPackages(); foreach ($packages as $package) { if ($drupalType = $this->getDrupalType($package)) { if (!isset($typePathMap[$drupalType])) { continue; } $installPath = self::changeSlashes($im->getInstaller($package->getType())->getInstallPath($package)); if (strpos($installPath, $root = $this->getRoot()) !== false) { $installPath = self::changeSlashes($this->getFS()->makePathRelative($installPath, $root)); } $name = explode('/', $package->getPrettyName())[1]; $mapRef =& $typeInstallMap[$drupalType][rtrim($installPath, DIRECTORY_SEPARATOR)]; if (in_array($drupalType, ['module', 'theme'])) { $mapRef = sprintf($typePathMap[$drupalType] . DIRECTORY_SEPARATOR . '%s', 'contrib', $name); } else { $mapRef = sprintf($typePathMap[$drupalType], $name); } } } return array_intersect_key($typeInstallMap, $typePathMap); }
function getInstaller($packageType) { // if we don't support this type at all, move along to the rest of the installers if (!$this->wpInstaller->supports($packageType)) { $this->io->write("Composer-WP installer does not support {$packageType}", true, IOInterface::DEBUG); return parent::getInstaller($packageType); } // if we explicitly support this type, return the WP installer if ($this->wpInstaller->prioritySupports($packageType)) { $this->io->write("Composer-WP installer explicitly supports {$packageType}", true, IOInterface::DEBUG); return $this->wpInstaller; } // otherwise, check to see if there is another installer that supports this type before we claim it try { // this may throw an InvalidArgumentException if no installer is found, but // LibraryInstaller is a floozie and will take any package it can get its hands on $installer = parent::getInstaller($packageType); $class = get_class($installer); // is the selected installer just the default one? if ($class === 'Composer\\Installer\\LibraryInstaller') { throw new \InvalidArgumentException(); } $this->io->write("Composer-WP installer supports {$packageType} but gives priority to {$class}", true, IOInterface::DEBUG); // set the path to false so we do not try again $this->wpInstaller->setPath($packageType, false); return $installer; } catch (\InvalidArgumentException $e) { $this->io->write("Composer-WP installer claims support for {$packageType}", true, IOInterface::DEBUG); // no custom installer, let's take charge! $this->wpInstaller->setPath($packageType); return $this->wpInstaller; } }
/** * {@inheritDoc} * * @param string $packageType * @return bool */ public function supports($packageType) { try { return $this->installManager->getInstaller($packageType) instanceof InstallerInterface; } catch (\InvalidArgumentException $e) { return false; } }
public function testAddRemoveInstaller() { $installer = $this->createInstallerMock(); $installer->expects($this->exactly(2))->method('supports')->will($this->returnCallback(function ($arg) { return $arg === 'vendor'; })); $installer2 = $this->createInstallerMock(); $installer2->expects($this->exactly(1))->method('supports')->will($this->returnCallback(function ($arg) { return $arg === 'vendor'; })); $manager = new InstallationManager(); $manager->addInstaller($installer); $this->assertSame($installer, $manager->getInstaller('vendor')); $manager->addInstaller($installer2); $this->assertSame($installer2, $manager->getInstaller('vendor')); $manager->removeInstaller($installer2); $this->assertSame($installer, $manager->getInstaller('vendor')); }
public function mapContrib(InstallationManager $im, RepositoryManager $rm) { $typePathMap = $this->getTypePathMap(); $typeInstallMap = []; $packages = $rm->getLocalRepository()->getCanonicalPackages(); foreach ($packages as $package) { if ($drupalType = $this->getDrupalType($package)) { $installPath = $im->getInstaller($package->getType())->getInstallPath($package); if (strpos($installPath, $root = $this->getRoot()) !== false) { $installPath = $this->getFS()->makePathRelative($installPath, $root); } $name = explode('/', $package->getPrettyName())[1]; $typeInstallMap[$drupalType][rtrim($installPath, '/')] = sprintf($typePathMap[$drupalType] . '/%s', 'contrib', $name); } } return array_intersect_key($typeInstallMap, $typePathMap); }