/** * {@inheritdoc} */ public function addRootAssetMapping(AssetMapping $mapping, $flags = 0) { if (!($flags & self::IGNORE_SERVER_NOT_FOUND) && !$this->servers->contains($mapping->getServerName())) { throw NoSuchServerException::forServerName($mapping->getServerName()); } if (!($flags & self::OVERRIDE) && $this->hasAssetMapping($mapping->getUuid())) { throw DuplicateAssetMappingException::forUuid($mapping->getUuid()); } $this->discoveryManager->addRootBinding(new BindingDescriptor($mapping->getGlob() . '{,/**/*}', DiscoveryUrlGenerator::BINDING_TYPE, array(DiscoveryUrlGenerator::SERVER_PARAMETER => $mapping->getServerName(), DiscoveryUrlGenerator::PATH_PARAMETER => $mapping->getServerPath()), 'glob', $mapping->getUuid()), $flags & self::OVERRIDE ? DiscoveryManager::OVERRIDE : 0); }
/** * {@inheritdoc} */ public function addRootAssetMapping(AssetMapping $mapping, $flags = 0) { if (!$this->discoveryManager->hasTypeDescriptor(DiscoveryUrlGenerator::BINDING_TYPE)) { throw new RuntimeException(sprintf('The binding type "%s" was not found. Please install the ' . '"puli/url-generator" package with Composer:' . "\n\n" . ' $ composer require puli/url-generator', DiscoveryUrlGenerator::BINDING_TYPE)); } if (!($flags & self::IGNORE_SERVER_NOT_FOUND) && !$this->servers->contains($mapping->getServerName())) { throw NoSuchServerException::forServerName($mapping->getServerName()); } if (!($flags & self::OVERRIDE) && $this->hasAssetMapping($mapping->getUuid())) { throw DuplicateAssetMappingException::forUuid($mapping->getUuid()); } $binding = new ResourceBinding($mapping->getGlob() . '{,/**/*}', DiscoveryUrlGenerator::BINDING_TYPE, array(DiscoveryUrlGenerator::SERVER_PARAMETER => $mapping->getServerName(), DiscoveryUrlGenerator::PATH_PARAMETER => $mapping->getServerPath()), 'glob', $mapping->getUuid()); $this->discoveryManager->addRootBindingDescriptor(new BindingDescriptor($binding), $flags & self::OVERRIDE ? DiscoveryManager::OVERRIDE : 0); if ($this->dispatcher && $this->dispatcher->hasListeners(PuliEvents::POST_ADD_ASSET_MAPPING)) { $this->dispatcher->dispatch(PuliEvents::POST_ADD_ASSET_MAPPING, new AddAssetMappingEvent($mapping)); } }
/** * @expectedException \Puli\Manager\Api\Installation\NotInstallableException * @expectedExceptionMessage Puli\Manager\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'))); $server = new Server('example.com', 'rsync', 'ssh://server/public_html', '/%s', array('param1' => 'custom1', 'param3' => 'custom2')); $mapping = new AssetMapping('/path/{css,js}', 'example.com', 'assets'); $this->servers->add($server); $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(); $serverName = $mapping->getServerName(); $resources = $this->repo->find($glob); if ($resources->isEmpty()) { throw NotInstallableException::noResourceMatches($glob); } if (!$this->servers->contains($serverName)) { throw NotInstallableException::serverNotFound($serverName); } $server = $this->servers->get($serverName); $installerName = $server->getInstallerName(); if (!$this->installerManager->hasInstallerDescriptor($installerName)) { throw NotInstallableException::installerNotFound($installerName); } $installerDescriptor = $this->installerManager->getInstallerDescriptor($installerName); $installer = $this->loadInstaller($installerDescriptor); $rootDir = $this->context->getRootDirectory(); $params = new InstallationParams($installer, $installerDescriptor, $resources, $mapping, $server, $rootDir); $installer->validateParams($params); return $params; }
private function assertServersLoaded() { if (null !== $this->servers) { return; } $serversData = $this->rootPackageFileManager->getExtraKey(self::SERVERS_KEY); if ($serversData) { $jsonValidator = new JsonValidator(); $errors = $jsonValidator->validate($serversData, __DIR__ . '/../../res/schema/servers-schema-1.0.json'); if (count($errors) > 0) { throw new ValidationFailedException(sprintf("The extra key \"%s\" is invalid:\n%s", self::SERVERS_KEY, implode("\n", $errors))); } } $this->servers = new ServerCollection(); $this->serversData = (array) $serversData; foreach ($this->serversData as $serverName => $serverData) { $this->servers->add($this->dataToServer($serverName, $serverData)); } }
public function testGetServerNames() { $this->collection->add($this->server1); $this->collection->add($this->server2); $this->assertSame(array('server1', 'server2'), $this->collection->getServerNames()); }