/** * 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); }