Exemplo n.º 1
0
 /**
  * {@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));
 }
Exemplo n.º 2
0
    /**
     * {@inheritDoc}
     */
    public function isStored($path, $filter)
    {
        $cacheKey = $this->generateCacheKey($path, $filter);

        return
            $this->cache->contains($cacheKey) ||
            $this->resolver->isStored($path, $filter)
        ;
    }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function isStored($path, $filter)
 {
     return $this->resolver->isStored($path, $filter);
 }
 public function isStored($path, $filter)
 {
     $path = $this->rewritePath($path);
     return $this->resolver->isStored($path, $filter);
 }