From 28cf0256ad7da0b4de73c62d3e2e1da35e0c803e Mon Sep 17 00:00:00 2001 From: Jonas Drieghe Date: Fri, 8 Oct 2021 12:41:04 +0200 Subject: [PATCH 1/2] Use new ServerVariables collection class to pass server variables to share method --- src/HtaccessClient.php | 7 +++---- tests/HtaccessClientTest.php | 5 ++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/HtaccessClient.php b/src/HtaccessClient.php index a3b591a..beb419c 100644 --- a/src/HtaccessClient.php +++ b/src/HtaccessClient.php @@ -57,17 +57,16 @@ function (array $line) { public function share( string $url, string $htaccess, - ?string $referrer = '', - ?string $serverName = '' + ?ServerVariables $serverVariables = null ): ShareResult { + $serverVariables = $serverVariables ?? ServerVariables::default(); $responseData = $this->request( 'POST', '/share', [ 'url' => $url, 'htaccess' => $htaccess, - 'referrer' => $referrer ?? '', - 'server_name' => $serverName ?? '', + 'serverVariables' => $serverVariables->toArray() ] ); diff --git a/tests/HtaccessClientTest.php b/tests/HtaccessClientTest.php index 5ae9c5b..b048241 100644 --- a/tests/HtaccessClientTest.php +++ b/tests/HtaccessClientTest.php @@ -189,7 +189,7 @@ public function it can share a test run with a referer(): void 'http://localhost', 'RewriteCond %{HTTP_REFERER} http://example.com RewriteRule .* /example-page [L]', - 'http://example.com' + ServerVariables::default()->with(ServerVariable::HTTP_REFERER, 'http://example.com') ); $this->assertStringStartsWith( @@ -222,8 +222,7 @@ public function it can share a test run with a server name(): void 'http://localhost', 'RewriteCond %{SERVER_NAME} example.com RewriteRule .* /example-page [L]', - null, - 'example.com' + ServerVariables::default()->with(ServerVariable::SERVER_NAME, 'example.com') ); $this->assertStringStartsWith( From d28498b46d393362bf29fd248a2c6cd090bc3bbe Mon Sep 17 00:00:00 2001 From: Jonas Drieghe Date: Fri, 8 Oct 2021 12:42:20 +0200 Subject: [PATCH 2/2] Add documentation about passing ServerVariables to share() method --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c9fcda..7feefbd 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ HTTP_REFERER SERVER_NAME ``` -Server variables can be passed to the `test()` method. +Server variables can be passed to the `test()` and `share()` methods. ```php $serverVariables = ServerVariables::default()->with( ServerVariable::SERVER_NAME, @@ -72,4 +72,11 @@ $response = $client->test( RewriteRule .* /foo [R]', $serverVariables ); + +$response = $client->share( + 'http://localhost', + 'RewriteCond %{SERVER_NAME} example.com + RewriteRule .* /foo [R]', + $serverVariables +); ```