File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -33,13 +33,19 @@ final class Rules
33
33
/**
34
34
* Returns a new instance from a file path.
35
35
*
36
- * @param string $path
36
+ * @param string $path
37
+ * @param null|resource $context
37
38
*
38
39
* @return self
39
40
*/
40
- public static function createFromPath (string $ path ): self
41
+ public static function createFromPath (string $ path, $ context = null ): self
41
42
{
42
- if (!($ resource = @fopen ($ path , 'r ' ))) {
43
+ $ args = [$ path , 'r ' , false ];
44
+ if (null !== $ context ) {
45
+ $ args [] = $ context ;
46
+ }
47
+
48
+ if (!($ resource = @fopen (...$ args ))) {
43
49
throw new Exception (sprintf ('`%s`: failed to open stream: No such file or directory ' , $ path ));
44
50
}
45
51
Original file line number Diff line number Diff line change @@ -27,7 +27,14 @@ public function setUp()
27
27
28
28
public function testCreateFromPath ()
29
29
{
30
- $ rules = Rules::createFromPath (__DIR__ .'/data/public_suffix_list.dat ' );
30
+ $ context = stream_context_create ([
31
+ 'http ' => [
32
+ 'method ' => 'GET ' ,
33
+ 'header ' => "Accept-language: en \r\nCookie: foo=bar \r\n" ,
34
+ ],
35
+ ]);
36
+
37
+ $ rules = Rules::createFromPath (__DIR__ .'/data/public_suffix_list.dat ' , $ context );
31
38
$ this ->assertInstanceOf (Rules::class, $ rules );
32
39
}
33
40
You can’t perform that action at this time.
0 commit comments