Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function publish($filename, $destination, $merge = self::FOLLOW, $mode = FilesInterface::READONLY)
 {
     if (!$this->files->isFile($filename)) {
         throw new PublishException("Given '{$filename}' is not valid file.");
     }
     //wtf? always empty
     if (empty($relativeFilename)) {
         $relativeFilename = $this->files->normalizePath($this->files->relativePath($filename, $this->directories->directory('root')));
     }
     //wtf?
     if (empty($relativeDestination)) {
         $relativeDestination = $this->files->relativePath($destination, $this->directories->directory('root'));
     }
     if ($this->files->exists($destination)) {
         if ($this->files->md5($destination) == $this->files->md5($filename)) {
             $this->logger()->debug("File '{relativeFilename}' already published and latest version.", compact('relativeFilename', 'destination'));
             //Nothing to do
             return;
         }
         if ($merge == self::FOLLOW) {
             //We are not allowed to replace file
             $this->logger()->warning("File '{relativeFilename}' already published and can not be replaced.", compact('relativeFilename', 'destination'));
             return;
         }
     }
     $this->logger()->info("Publish file '{relativeFilename}' to '{relativeDestination}'.", compact('relativeFilename', 'relativeDestination'));
     $this->ensureDirectory(dirname($destination), $mode);
     $this->files->copy($filename, $destination);
     $this->files->setPermissions($destination, $mode);
 }
Beispiel #2
0
 /**
  * Create stream for given filename.
  *
  * @param string|StreamInterface|StreamableInterface $filename
  * @return StreamInterface
  */
 private function getStream($filename)
 {
     if ($filename instanceof StreamableInterface) {
         return $filename->getStream();
     }
     if ($filename instanceof StreamInterface) {
         return $filename;
     }
     if (is_resource($filename)) {
         return new Stream($filename, 'r');
     }
     if (!$this->files->isFile($filename)) {
         throw new \InvalidArgumentException("Unable to allocate response body stream, file does not exist.");
     }
     return new Stream(fopen($this->files->localUri($filename), 'r'));
 }