Example #1
0
 /**
  * @param NodeInterface $node
  *
  * @return FileNode
  */
 public function flow(NodeInterface $node)
 {
     if (!$node instanceof FileNode) {
         throw new InvalidArgumentException("Node: {$node} should be an instance of FileNode");
     }
     if (substr($this->target->getPath(), -1) == '/') {
         $target = $this->target->getClone()->setPath($this->target->getPath() . $node->getFilename());
     } else {
         $target = $this->target;
     }
     return $this->copyTo($node, $target);
 }
Example #2
0
 /**
  * FileReader constructor.
  *
  * @param FileNodeInterface              $file
  * @param FormatInterface|null           $format
  * @param FormatterFactoryInterface|null $formatterFactory
  */
 public function __construct(FileNodeInterface $file, FormatInterface $format = null, FormatterFactoryInterface $formatterFactory = null)
 {
     if ($file instanceof NodeStreamInterface) {
         $stream = $file->getStream('c+b');
     } else {
         throw new InvalidArgumentException("Only files that implement " . NodeStreamInterface::class . "can be written to");
     }
     if (is_null($format) && $file instanceof FormatAwareInterface) {
         $format = $file->getFormat();
     }
     if (is_null($format)) {
         throw new InvalidArgumentException("No format could be determined from \$file or \$format");
     }
     $factory = $formatterFactory ?: new FormatterFactory();
     $formatter = $factory->getFormatter($format);
     parent::__construct($stream, $formatter);
 }
Example #3
0
 /**
  * FileReader constructor.
  *
  * @param FileNodeInterface           $file
  * @param FormatInterface|null        $format
  * @param ParserFactoryInterface|null $parserFactory
  */
 public function __construct(FileNodeInterface $file, FormatInterface $format = null, ParserFactoryInterface $parserFactory = null)
 {
     if ($file instanceof NodeStreamInterface) {
         $stream = $file->getStream('r');
     } else {
         $stream = new Stream($file->readStream());
     }
     if (is_null($format) && $file instanceof FormatAwareInterface) {
         $format = $file->getFormat();
     }
     if (is_null($format)) {
         throw new InvalidArgumentException("No format could be determined from \$file or \$format");
     }
     $factory = $parserFactory ?: new ParserFactory();
     $parser = $factory->getParser($format);
     parent::__construct($stream, $parser);
 }
Example #4
0
 /**
  * Can this file be modified by this modifier
  *
  * @param FileNodeInterface $file
  *
  * @return bool
  */
 public function canModify(FileNodeInterface $file)
 {
     return $file->exists() && $file instanceof FormatAwareInterface && $file->getFormat() !== null && $this->parserFactory->getParser($file->getFormat()) !== null;
 }
Example #5
0
 /**
  * Can this file be modified by this modifier
  *
  * @param FileNodeInterface $file
  *
  * @return bool
  */
 public function canModify(FileNodeInterface $file)
 {
     return $file instanceof LocalFile && $file->exists();
 }
 /**
  * MakeDirectoryFailedException constructor.
  *
  * @param FileNodeInterface $file
  * @param string            $message
  * @param Exception|null    $previous
  */
 public function __construct(FileNodeInterface $file, $message = '', Exception $previous = null)
 {
     $message = "Failed to create directory: '{$file->getDirectory()}'. " . $message;
     parent::__construct($message, 0, $previous);
 }