/** * {@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)); } }
/** * Handles the "bind --update <uuid>" command. * * @param Args $args The console arguments. * * @return int The status code. */ public function handleUpdate(Args $args) { $flags = $args->isOptionSet('force') ? DiscoveryManager::OVERRIDE | DiscoveryManager::IGNORE_TYPE_NOT_FOUND | DiscoveryManager::IGNORE_TYPE_NOT_ENABLED : DiscoveryManager::OVERRIDE; $descriptorToUpdate = $this->getBindingByUuidPrefix($args->getArgument('uuid')); $bindingToUpdate = $descriptorToUpdate->getBinding(); if (!$descriptorToUpdate->getContainingPackage() instanceof RootPackage) { throw new RuntimeException(sprintf('Can only update bindings in the package "%s".', $this->packages->getRootPackageName())); } if ($bindingToUpdate instanceof ResourceBinding) { $updatedBinding = $this->getUpdatedResourceBinding($args, $bindingToUpdate); } elseif ($bindingToUpdate instanceof ClassBinding) { $updatedBinding = $this->getUpdatedClassBinding($args, $bindingToUpdate); } else { throw new RuntimeException(sprintf('Cannot update bindings of type %s.', get_class($bindingToUpdate))); } $updatedDescriptor = new BindingDescriptor($updatedBinding); if ($this->bindingsEqual($descriptorToUpdate, $updatedDescriptor)) { throw new RuntimeException('Nothing to update.'); } $this->discoveryManager->addRootBindingDescriptor($updatedDescriptor, $flags); return 0; }