function testCreateWithUuid()
 {
     $uuid = Uuid::uuid4();
     $mapping = new AssetMapping('/blog/public', 'local', '/blog', $uuid);
     $this->assertSame('/blog/public', $mapping->getGlob());
     $this->assertSame('local', $mapping->getServerName());
     $this->assertSame('/blog', $mapping->getServerPath());
     $this->assertSame($uuid, $mapping->getUuid());
 }
 /**
  * {@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);
 }
 /**
  * Creates the installation request.
  *
  * @param ResourceInstaller   $installer           The used resource installer.
  * @param InstallerDescriptor $installerDescriptor The descriptor of the
  *                                                 resource installer.
  * @param ResourceCollection  $resources           The resources to install.
  * @param AssetMapping        $mapping             The asset mapping.
  * @param Server              $server              The asset server.
  * @param string              $rootDir             The project's root directory.
  */
 public function __construct(ResourceInstaller $installer, InstallerDescriptor $installerDescriptor, ResourceCollection $resources, AssetMapping $mapping, Server $server, $rootDir)
 {
     $glob = $mapping->getGlob();
     $parameterValues = $server->getParameterValues();
     $this->validateParameterValues($parameterValues, $installerDescriptor);
     $this->installer = $installer;
     $this->installerDescriptor = $installerDescriptor;
     $this->resources = $resources;
     $this->mapping = $mapping;
     $this->server = $server;
     $this->rootDir = $rootDir;
     $this->basePath = Glob::isDynamic($glob) ? Glob::getBasePath($glob) : $glob;
     $this->parameterValues = array_replace($installerDescriptor->getParameterValues(), $parameterValues);
 }
 /**
  * {@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));
     }
 }
 /**
  * {@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;
 }
 public function testUpdateMappingForce()
 {
     $args = self::$updateCommand->parseArgs(new StringArgs('abcd --path /new --force'));
     $mapping = new AssetMapping('/app/public', 'localhost', '/');
     $uuid = $mapping->getUuid();
     $this->assetManager->expects($this->once())->method('findAssetMappings')->with(Expr::startsWith('abcd', AssetMapping::UUID))->willReturn(array($mapping));
     $this->assetManager->expects($this->once())->method('addRootAssetMapping')->willReturnCallback(function (AssetMapping $mapping, $flags) use($uuid) {
         PHPUnit_Framework_Assert::assertSame('/new', $mapping->getGlob());
         PHPUnit_Framework_Assert::assertSame('localhost', $mapping->getServerName());
         PHPUnit_Framework_Assert::assertSame('/', $mapping->getServerPath());
         PHPUnit_Framework_Assert::assertSame($uuid, $mapping->getUuid());
         PHPUnit_Framework_Assert::assertSame(AssetManager::OVERRIDE | AssetManager::IGNORE_SERVER_NOT_FOUND, $flags);
     });
     $this->assertSame(0, $this->handler->handleUpdate($args));
 }
Example #7
0
 private function mappingsEqual(AssetMapping $mapping1, AssetMapping $mapping2)
 {
     if ($mapping1->getUuid() !== $mapping2->getUuid()) {
         return false;
     }
     if ($mapping1->getGlob() !== $mapping2->getGlob()) {
         return false;
     }
     if ($mapping1->getServerPath() !== $mapping2->getServerPath()) {
         return false;
     }
     if ($mapping1->getServerName() !== $mapping2->getServerName()) {
         return false;
     }
     return true;
 }
Example #8
0
 private function mappingsEqual(AssetMapping $mapping1, AssetMapping $mapping2)
 {
     return $mapping1->getUuid() === $mapping2->getUuid() && $mapping1->getGlob() === $mapping2->getGlob() && $mapping1->getServerPath() === $mapping2->getServerPath() && $mapping1->getServerName() === $mapping2->getServerName();
 }