1<?php 2namespace GuzzleHttp\Stream; 3 4/** 5 * Lazily reads or writes to a file that is opened only after an IO operation 6 * take place on the stream. 7 */ 8class LazyOpenStream implements StreamInterface 9{ 10 use StreamDecoratorTrait; 11 12 /** @var string File to open */ 13 private $filename; 14 15 /** @var string $mode */ 16 private $mode; 17 18 /** 19 * @param string $filename File to lazily open 20 * @param string $mode fopen mode to use when opening the stream 21 */ 22 public function __construct($filename, $mode) 23 { 24 $this->filename = $filename; 25 $this->mode = $mode; 26 } 27 28 /** 29 * Creates the underlying stream lazily when required. 30 * 31 * @return StreamInterface 32 */ 33 protected function createStream() 34 { 35 return Stream::factory(Utils::open($this->filename, $this->mode)); 36 } 37} 38