Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function teleport(Resource $resource, $context)
 {
     $target = $this->resourceLocator->mapResourcePath($resource, $context);
     $path = $resource->getOriginal();
     if (!file_exists($path)) {
         throw new InvalidArgumentException(sprintf('Invalid path %s', $path));
     }
     try {
         if (is_file($path)) {
             $this->filesystem->copy($path, $target);
         } elseif (is_dir($path)) {
             $this->filesystem->mirror($path, $target);
         } else {
             throw new InvalidArgumentException(sprintf('Invalid file or directory %s', $path));
         }
     } catch (SfIOException $e) {
         throw new IOException(sprintf('Could not write %s', $target), $e->getCode(), $e);
     }
 }
Ejemplo n.º 2
0
 /**
  * Teleports a file from a destination to an other
  *
  * @param \Alchemy\Zippy\Resource\Resource $resource A Resource
  * @param string $context The current context
  *
  * @throws IOException when file could not be written on local
  * @throws InvalidArgumentException when path to file is not valid
  */
 public function teleport(Resource $resource, $context)
 {
     $reader = $this->readerFactory->getReader($resource, $context);
     $target = $this->resourceLocator->mapResourcePath($resource, $context);
     $this->resourceWriter->writeFromReader($reader, $target);
 }