Skip to content

Commit 63dc577

Browse files
committed
adding context argument to Rules::createFromPath
1 parent fca2a87 commit 63dc577

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/Rules.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,19 @@ final class Rules
3333
/**
3434
* Returns a new instance from a file path.
3535
*
36-
* @param string $path
36+
* @param string $path
37+
* @param null|resource $context
3738
*
3839
* @return self
3940
*/
40-
public static function createFromPath(string $path): self
41+
public static function createFromPath(string $path, $context = null): self
4142
{
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))) {
4349
throw new Exception(sprintf('`%s`: failed to open stream: No such file or directory', $path));
4450
}
4551

tests/RulesTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ public function setUp()
2727

2828
public function testCreateFromPath()
2929
{
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);
3138
$this->assertInstanceOf(Rules::class, $rules);
3239
}
3340

0 commit comments

Comments
 (0)