/** * Create a reader instance from a stream-wrapped source * * @param string $src Stream-wrapped source * @param string $resourceClass Resource class name * @param array $parameters Reader parameters * @return AbstractResource Resource instance * @throws InvalidReaderArgumentException If an invalid reader stream wrapper is given */ protected static function fromSource($src, $resourceClass, ...$parameters) { $reader = Tools::reader($src, $parameters); if ($reader instanceof ReaderInterface) { return Kernel::create($resourceClass, [$reader]); } throw new InvalidArgumentException('Invalid reader stream wrapper', InvalidReaderArgumentException::INVALID_READER_STREAM_WRAPPER); }
/** * Dump this file to a stream-wrapped target * * @param string $target Stream-wrapped target * @param array $parameters Writer parameters * @return WriterInterface Writer instance * @throws InvalidWriterArgumentException If an invalid reader stream wrapper is given */ public function toTarget($target, ...$parameters) { $writer = Tools::writer($target, $parameters); if ($writer instanceof WriterInterface) { $this->dump($writer); return $writer; } throw new InvalidArgumentException('Invalid writer stream wrapper', InvalidWriterArgumentException::INVALID_WRITER_STREAM_WRAPPER); }
/** * Copy the source resource to a target resource * * @param string $target Stream wrapped target * @param array $parameters Writer parameters * @return WriterInterface Writer instance * @throws InvalidWriterArgumentException If the writer stream wrapper is invalid */ public function toTarget($target, ...$parameters) { $writer = Tools::writer($target, $parameters); // If it's a file writer if ($writer instanceof FileWriter) { return $this->copyToFile($writer); } // If it's an in-memory writer if ($writer instanceof InMemoryWriter) { return $this->copyToInMemory($writer); } throw new InvalidArgumentException('Invalid writer stream wrapper', InvalidWriterArgumentException::INVALID_WRITER_STREAM_WRAPPER); }