Beispiel #1
0
 /**
  * Create a target file from a source file and postfix
  *
  * @param LocalFileNodeInterface $file
  * @param string                 $postfix
  *
  * @return LocalFileNodeInterface
  */
 protected function getTargetFile(LocalFileNodeInterface $file, $postfix)
 {
     if (strlen($postfix) > 0) {
         $postfix = '-' . $postfix;
     }
     $pathInfo = pathinfo($file->getPath());
     $extension = isset($pathInfo['extension']) ? '.' . $pathInfo['extension'] : '';
     $path = sprintf('%s/%s%s%s', $pathInfo['dirname'], $pathInfo['filename'], $postfix, $extension);
     return $file->getClone()->setPath($path);
 }
Beispiel #2
0
 /**
  * Compress a file and return the new file
  *
  * @param LocalFileNodeInterface $node
  * @param array                  $options
  *
  * @return LocalFileNodeInterface
  */
 public function compress(LocalFileNodeInterface $node, array $options = [])
 {
     $pathInfo = pathinfo($node->getPath());
     if (!$node->exists()) {
         throw new InvalidArgumentException("The file: {$node} does not exist");
     }
     $outputFile = $node->getClone()->setPath($pathInfo['dirname'] . '/' . $pathInfo['filename'] . '.' . $this->getExtension())->setCompression($this->getName());
     $this->log(LogLevel::INFO, "Compressing file: {file} into {target} using {compression}", ['file' => $node, 'target' => $outputFile, 'compression' => $this->getName()]);
     $cmd = $this->getCompressCommand($node, $outputFile);
     $keepOld = isset($options['keepOldFile']) ? $options['keepOldFile'] : true;
     return $this->processFile($node, $outputFile, $cmd, $keepOld);
 }