/** * Returns the server with the given name. * * @param string $serverName The server name. * * @return Server The server. * * @throws NoSuchServerException If the server does not exist. */ public function get($serverName) { if (!isset($this->servers[$serverName])) { throw NoSuchServerException::forServerName($serverName); } return $this->servers[$serverName]; }
/** * {@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)); } }
public function handleDelete(Args $args) { $serverName = $args->getArgument('name'); if (!$this->serverManager->hasServer($serverName)) { throw NoSuchServerException::forServerName($serverName); } $this->serverManager->removeServer($serverName); return 0; }