Ejemplo n.º 1
0
 /**
  * Applies dump filters and returns the asset as a string.
  *
  * @param  FilterInterface|null $additionalFilter
  * @return string
  */
 public function dump(FilterInterface $additionalFilter = null)
 {
     $cacheKey = $this->getCacheKey($this->asset, $additionalFilter, 'dump');
     if ($this->cache->has($cacheKey)) {
         return $this->cache->get($cacheKey);
     }
     $content = $this->asset->dump($additionalFilter);
     $this->cache->set($cacheKey, $content);
     return $content;
 }
 /**
  * Copy a file to the directory.
  *
  * @param string  $file  fullpath of file to add
  * @param boolean $force ignore cache and add file to directory
  *
  * @throws InvalidArgumentException file does not exist
  * @throws RuntimeException filesystem errors
  *
  * @return string target image path
  */
 public function add($file, $force = false)
 {
     if (!file_exists($file)) {
         throw new \InvalidArgumentException(sprintf('File "%s" does not exist.', $file));
     }
     if (false === $force && null !== ($path = $this->getCache($file))) {
         return null === $this->target ? $path : $this->target . '/' . $path;
     }
     $name = $this->findAvailableName($file);
     if (null !== $this->cache) {
         $this->cache->set(md5($file), serialize(array(filemtime($file), $name)));
     }
     if (!is_dir($dir = dirname($target = $this->directory . '/' . $name))) {
         mkdir($dir, 0777, true);
     }
     if (false === @copy($file, $target)) {
         throw new \RuntimeException(sprintf('Error while copying "%s" to "%s".', $file, $target));
     }
     return null === $this->target ? $name : $this->target . '/' . $name;
 }
 /**
  * Proxy set to use the underlying cache driver
  *
  * @param string $key
  * @param string $value
  */
 public function set($key, $value)
 {
     return $this->cache->set($key, $value);
 }