/** * Adds a resolver to handle cached images for the given filter. * * @param string $filter * @param ResolverInterface $resolver */ public function addResolver($filter, ResolverInterface $resolver) { $this->resolvers[$filter] = $resolver; if ($resolver instanceof CacheManagerAwareInterface) { $resolver->setCacheManager($this); } }
public function testProxyCallOnRemove() { $expectedPaths = array('thePath'); $expectedFilters = array('theFilter'); $this->primaryResolver->expects($this->once())->method('remove')->with($expectedPaths, $expectedFilters); $this->resolver->remove($expectedPaths, $expectedFilters); }
/** * {@inheritdoc} * * @throws \InvalidArgumentException If field value is not an instance of \eZ\Publish\Core\FieldType\Image\Value. * @throws \eZ\Publish\Core\MVC\Exception\SourceImageNotFoundException If source image cannot be found. * @throws \eZ\Publish\API\Repository\Exceptions\InvalidVariationException If a problem occurs with generated variation. */ public function getVariation(Field $field, VersionInfo $versionInfo, $variationName, array $parameters = array()) { /** @var \eZ\Publish\Core\FieldType\Image\Value $imageValue */ $imageValue = $field->value; $fieldId = $field->id; $fieldDefIdentifier = $field->fieldDefIdentifier; if (!$this->supportsValue($imageValue)) { throw new InvalidArgumentException("Value for field #{$fieldId} ({$fieldDefIdentifier}) cannot be used for image alias generation."); } $originalPath = $imageValue->id; // Create the image alias only if it does not already exist. if ($variationName !== IORepositoryResolver::VARIATION_ORIGINAL && !$this->ioResolver->isStored($originalPath, $variationName)) { try { $originalBinary = $this->dataLoader->find($originalPath); } catch (NotLoadableException $e) { throw new SourceImageNotFoundException($originalPath, 0, $e); } if ($this->logger) { $this->logger->debug("Generating '{$variationName}' variation on {$originalPath}, field #{$fieldId} ({$fieldDefIdentifier})"); } $this->ioResolver->store($this->applyFilter($originalBinary, $variationName), $originalPath, $variationName); } elseif ($this->logger) { $this->logger->debug("'{$variationName}' variation on {$originalPath} is already generated. Loading from cache."); } try { $aliasInfo = new SplFileInfo($this->ioResolver->resolve($originalPath, $variationName)); } catch (NotResolvableException $e) { // If for some reason image alias cannot be resolved, throw the appropriate exception. throw new InvalidVariationException($variationName, 'image', 0, $e); } return new ImageVariation(array('name' => $variationName, 'fileName' => $aliasInfo->getFilename(), 'dirPath' => $aliasInfo->getPath(), 'uri' => $aliasInfo->getPathname(), 'imageId' => $imageValue->imageId)); }
/** * {@inheritDoc} */ public function remove(array $paths, array $filters) { $this->resolver->remove($paths, $filters); foreach ($filters as $filter) { if (empty($paths)) { $this->removePathAndFilter(null, $filter); } else { foreach ($paths as $path) { $this->removePathAndFilter($path, $filter); } } } }
/** * {@inheritDoc} */ public function remove($targetPath, $filter) { $removed = $this->resolver->remove($targetPath, $filter); // If the resolver did not remove the content, we can leave the cache. if ($removed) { $reverseKey = $this->generateCacheKey('reverse', $targetPath, $filter); if ($this->cache->contains($reverseKey)) { $path = $this->cache->fetch($reverseKey); // The indexKey is not utilizing the method so the value is not important. $indexKey = $this->generateIndexKey($this->generateCacheKey(null, $path, $filter)); // Retrieve the index and remove the content from the cache. $index = $this->cache->fetch($indexKey); foreach ($index as $eachCacheKey) { $this->cache->delete($eachCacheKey); } // Remove the auxiliary keys. $this->cache->delete($indexKey); $this->cache->delete($reverseKey); } } return $removed; }
/** * {@inheritdoc} */ public function remove(array $paths, array $filters) { return $this->resolver->remove($paths, $filters); }
public function remove(array $paths, array $filters) { $this->resolver->remove(array_map([$this, 'rewritePath'], $paths), $filters); }
public function removeAliases($originalPath) { $this->aliasResolver->remove(array($originalPath), array()); }