/** * {@inheritdoc} */ public function addRootAssetMapping(AssetMapping $mapping, $flags = 0) { if (!($flags & self::IGNORE_TARGET_NOT_FOUND) && !$this->installTargets->contains($mapping->getTargetName())) { throw NoSuchTargetException::forTargetName($mapping->getTargetName()); } if (!($flags & self::OVERRIDE) && $this->hasAssetMapping($mapping->getUuid())) { throw DuplicateAssetMappingException::forUuid($mapping->getUuid()); } $this->discoveryManager->addRootBinding(new BindingDescriptor($mapping->getGlob() . '{,/**/*}', AssetPlugin::BINDING_TYPE, array(AssetPlugin::TARGET_PARAMETER => $mapping->getTargetName(), AssetPlugin::PATH_PARAMETER => $mapping->getWebPath()), 'glob', $mapping->getUuid()), $flags & self::OVERRIDE ? DiscoveryManager::OVERRIDE : 0); }
private function generateUrlForBinding(ResourceBinding $binding, $repositoryPath) { $bindingPath = Glob::getStaticPrefix($binding->getQuery()); $webBasePath = trim($binding->getParameterValue(AssetPlugin::PATH_PARAMETER), '/'); $webPath = substr_replace($repositoryPath, $webBasePath, 0, strlen($bindingPath)); $targetName = $binding->getParameterValue(AssetPlugin::TARGET_PARAMETER); if (!$this->targets->contains($targetName)) { throw new CannotGenerateUrlException(sprintf('The target "%s" mapped for path "%s" does not exist.', $targetName, $repositoryPath)); } $target = $this->targets->get($targetName); return sprintf($target->getUrlFormat(), ltrim($webPath, '/')); }
public function testAddCreateUrlGeneratorMethod() { $targets = new InstallTargetCollection(array(new InstallTarget('local', 'symlink', 'public_html', '/%s'), new InstallTarget('remote', 'rsync', 'ssh://example.com', 'http://example.com/%s', array('user' => 'webmozart', 'password' => 'password')))); $targets->setDefaultTarget('remote'); $this->targetManager->expects($this->any())->method('getTargets')->willReturn($targets); $class = new Clazz('Puli\\MyFactory'); $class->addImport(new Import('Puli\\Factory\\PuliFactory')); $class->addImplementedInterface('PuliFactory'); $class->setFilePath($this->tempFile); $this->generator->addCreateUrlGeneratorMethod($class); $writer = new ClassWriter(); $writer->writeClass($class); $expected = <<<EOF <?php namespace Puli; use Puli\\AssetPlugin\\Api\\Factory\\UrlGeneratorFactory; use Puli\\AssetPlugin\\Api\\Target\\InstallTarget; use Puli\\AssetPlugin\\Api\\Target\\InstallTargetCollection; use Puli\\AssetPlugin\\Api\\UrlGenerator\\AssetUrlGenerator; use Puli\\AssetPlugin\\UrlGenerator\\DiscoveryUrlGenerator; use Puli\\Discovery\\Api\\ResourceDiscovery; use Puli\\Factory\\PuliFactory; class MyFactory implements PuliFactory, UrlGeneratorFactory { /** * Creates the URL generator. * * @param ResourceDiscovery \$discovery The resource discovery to read from. * * @return AssetUrlGenerator The created URL generator. */ public function createUrlGenerator(ResourceDiscovery \$discovery) { \$targets = new InstallTargetCollection(array( new InstallTarget('local', 'symlink', 'public_html', '/%s', array()), new InstallTarget('remote', 'rsync', 'ssh://example.com', 'http://example.com/%s', array( 'user' => 'webmozart', 'password' => 'password', )), )); \$targets->setDefaultTarget('remote'); \$generator = new DiscoveryUrlGenerator(\$discovery, \$targets); return \$generator; } } EOF; $this->assertSame($expected, file_get_contents($this->tempFile)); }
public function testOnlyReplacePrefix() { $this->targets->add(new InstallTarget('local', 'symlink', 'public_html')); $binding = new EagerBinding('/path{,/**/*}', $this->resources, $this->bindingType, array(AssetPlugin::TARGET_PARAMETER => 'local', AssetPlugin::PATH_PARAMETER => '/css')); $this->discovery->expects($this->once())->method('findByPath')->with('/path/path/style.css', AssetPlugin::BINDING_TYPE)->willReturn(array($binding)); $this->assertSame('/css/path/style.css', $this->generator->generateUrl('/path/path/style.css')); }
public function testListTargets() { $targets = new InstallTargetCollection(array(new InstallTarget('local', 'symlink', 'public_html', '/%s'), new InstallTarget('remote', 'rsync', 'ssh://example.com', 'http://example.com/%s', array('user' => 'webmozart', 'password' => 'password')))); $targets->setDefaultTarget('remote'); $this->targetManager->expects($this->any())->method('getTargets')->willReturn($targets); $args = self::$listCommand->parseArgs(new StringArgs('')); $expected = <<<EOF local symlink public_html /%s * remote rsync ssh://example.com http://example.com/%s user="******" password="******" EOF; $this->assertSame(0, $this->handler->handleList($args, $this->io)); $this->assertSame($expected, $this->io->fetchOutput()); $this->assertEmpty($this->io->fetchErrors()); }
private function updateDefaultTargetData() { $defaultTarget = $this->targets->isEmpty() ? null : $this->targets->getDefaultTarget()->getName(); foreach ($this->targetsData as $targetName => &$data) { if ($targetName === $defaultTarget) { $data->default = true; } else { unset($data->default); } } }
/** * @expectedException \Puli\AssetPlugin\Api\Installation\NotInstallableException * @expectedExceptionMessage Puli\AssetPlugin\Tests\Installation\Fixtures\TestInstallerInvalid * @expectedExceptionCode 8 */ public function testFailIfInstallerClassInvalid() { $resources = new ArrayResourceCollection(array(new GenericResource('/path/css'), new GenericResource('/path/js'))); $installerDescriptor = new InstallerDescriptor('rsync', self::INSTALLER_CLASS_INVALID, null, array(new InstallerParameter('param1', InstallerParameter::REQUIRED), new InstallerParameter('param2', InstallerParameter::OPTIONAL, 'default1'), new InstallerParameter('param3', InstallerParameter::OPTIONAL, 'default2'))); $target = new InstallTarget('server', 'rsync', 'ssh://server/public_html', '/%s', array('param1' => 'custom1', 'param3' => 'custom2')); $mapping = new AssetMapping('/path/{css,js}', 'server', 'assets'); $this->targets->add($target); $this->repo->expects($this->any())->method('find')->with('/path/{css,js}')->willReturn($resources); $this->installerManager->expects($this->any())->method('hasInstallerDescriptor')->with('rsync')->willReturn(true); $this->installerManager->expects($this->any())->method('getInstallerDescriptor')->with('rsync')->willReturn($installerDescriptor); $this->manager->prepareInstallation($mapping); }
/** * {@inheritdoc} */ public function prepareInstallation(AssetMapping $mapping) { $glob = $mapping->getGlob(); $targetName = $mapping->getTargetName(); $resources = $this->repo->find($glob); if ($resources->isEmpty()) { throw NotInstallableException::noResourceMatches($glob); } if (!$this->installTargets->contains($targetName)) { throw NotInstallableException::targetNotFound($targetName); } $target = $this->installTargets->get($targetName); $installerName = $target->getInstallerName(); if (!$this->installerManager->hasInstallerDescriptor($installerName)) { throw NotInstallableException::installerNotFound($installerName); } $installerDescriptor = $this->installerManager->getInstallerDescriptor($installerName); $installer = $this->loadInstaller($installerDescriptor); $rootDir = $this->environment->getRootDirectory(); $params = new InstallationParams($installer, $installerDescriptor, $resources, $mapping, $target, $rootDir); $installer->validateParams($params); return $params; }
public function testContainsWithDefaultTarget() { $this->assertFalse($this->collection->contains(InstallTarget::DEFAULT_TARGET)); $this->collection->add($this->target1); $this->assertTrue($this->collection->contains(InstallTarget::DEFAULT_TARGET)); }