Example #1
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 #2
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);
 }