File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 1313namespace chillerlan \HTTP \Psr17 ;
1414
1515use chillerlan \HTTP \Psr7 \Stream ;
16+ use InvalidArgumentException ;
1617use Psr \Http \Message \{StreamFactoryInterface , StreamInterface };
18+ use RuntimeException ;
1719
1820final class StreamFactory implements StreamFactoryInterface{
1921
@@ -44,6 +46,15 @@ public function createStream(string $content = ''):StreamInterface{
4446 * @return \Psr\Http\Message\StreamInterface
4547 */
4648 public function createStreamFromFile (string $ filename , string $ mode = 'r ' ):StreamInterface {
49+
50+ if (empty ($ filename ) || !is_file ($ filename )){
51+ throw new RuntimeException ('invalid file ' );
52+ }
53+
54+ if (!isset (Stream::MODES_WRITE [$ mode ]) && !isset (Stream::MODES_READ [$ mode ])){
55+ throw new InvalidArgumentException ('invalid mode ' );
56+ }
57+
4758 return new Stream (fopen ($ filename , $ mode ));
4859 }
4960
You can’t perform that action at this time.
0 commit comments