/** * {@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); }
public function testUpdateMappingForce() { $args = self::$updateCommand->parseArgs(new StringArgs('abcd --path /new --force')); $mapping = new AssetMapping('/app/public', 'local', '/'); $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('/', $mapping->getWebPath()); PHPUnit_Framework_Assert::assertSame('local', $mapping->getTargetName()); PHPUnit_Framework_Assert::assertSame($uuid, $mapping->getUuid()); PHPUnit_Framework_Assert::assertSame(AssetManager::OVERRIDE | AssetManager::IGNORE_TARGET_NOT_FOUND, $flags); }); $this->assertSame(0, $this->handler->handleUpdate($args)); }
public function testCreateWithEmptyWebPath() { $mapping = new AssetMapping('/blog/public', 'local', ''); $this->assertSame('/', $mapping->getWebPath()); }
private function mappingsEqual(AssetMapping $mapping1, AssetMapping $mapping2) { if ($mapping1->getUuid() !== $mapping2->getUuid()) { return false; } if ($mapping1->getGlob() !== $mapping2->getGlob()) { return false; } if ($mapping1->getWebPath() !== $mapping2->getWebPath()) { return false; } if ($mapping1->getTargetName() !== $mapping2->getTargetName()) { return false; } return true; }
/** * Returns the install path of a resource in the target location. * * This is a path relative to the root of the target location. * * @param Resource $resource The resource. * * @return string The web path. */ public function getWebPathForResource(Resource $resource) { $relPath = Path::makeRelative($resource->getRepositoryPath(), $this->basePath); return '/' . trim($this->mapping->getWebPath() . '/' . $relPath, '/'); }