Skip to content

Commit 80703b4

Browse files
matijakovacevicJacobBennett
authored andcommitted
Add laravel 6 support (#36)
* add laravel 6 version constraint to composer.json * str_* functions deprecated, use Str facade instead
1 parent cbab330 commit 80703b4

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
],
1919
"require": {
2020
"php" : "^7.0",
21-
"illuminate/support": "^5.3",
22-
"illuminate/http": "^5.3",
21+
"illuminate/support": "~5.3|~6.0",
22+
"illuminate/http": "~5.3|~6.0",
2323
"symfony/dom-crawler": "^2.7|^3.0|^4.0",
2424
"symfony/css-selector": "^2.7|^3.0|^4.0"
2525
},

src/Middleware/AddHttp2ServerPush.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace JacobBennett\Http2ServerPush\Middleware;
44

55
use Closure;
6+
use Illuminate\Support\Str;
67
use Illuminate\Http\Request;
78
use Illuminate\Http\Response;
89
use Symfony\Component\DomCrawler\Crawler;
@@ -43,7 +44,7 @@ public function getConfig($key, $default=false) {
4344
}
4445
return config('http2serverpush.'.$key, $default);
4546
}
46-
47+
4748
/**
4849
* @param \Illuminate\Http\Response $response
4950
*
@@ -69,7 +70,7 @@ protected function generateAndAttachLinkHeaders(Response $response, $limit = nul
6970
return !preg_match('%('.$exclude_keywords->implode('|').')%i', $value);
7071
})
7172
->take($limit);
72-
73+
7374
$sizeLimit = $sizeLimit ?? max(1, intval($this->getConfig('size_limit', 32*1024)));
7475
$headersText = trim($headers->implode(','));
7576
while(strlen($headersText) > $sizeLimit) {
@@ -136,10 +137,10 @@ private function buildLinkHeaderString($url)
136137
];
137138

138139
$type = collect($linkTypeMap)->first(function ($type, $extension) use ($url) {
139-
return str_contains(strtoupper($url), $extension);
140+
return Str::contains(strtoupper($url), $extension);
140141
});
141-
142-
142+
143+
143144
if(!preg_match('%^https?://%i', $url)) {
144145
$basePath = $this->getConfig('base_path', '/');
145146
$url = $basePath . ltrim($url, $basePath);

tests/AddHttp2ServerPushTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace JacobBennett\Http2ServerPush\Test;
44

55
use Illuminate\Http\Request;
6+
use Illuminate\Support\Str;
67
use JacobBennett\Http2ServerPush\Middleware\AddHttp2ServerPush;
78
use Symfony\Component\HttpFoundation\Response;
89

@@ -14,7 +15,7 @@ public function setUp()
1415
$this->middleware = new AddHttp2ServerPush();
1516
}
1617

17-
18+
1819
/** @test */
1920
public function it_will_not_exceed_size_limit()
2021
{
@@ -27,7 +28,7 @@ public function it_will_not_exceed_size_limit()
2728
$this->assertTrue(strlen($response->headers->get('link')) <= $limit );
2829
$this->assertCount(1, explode(",", $response->headers->get('link')));
2930
}
30-
31+
3132
/** @test */
3233
public function it_will_not_add_excluded_asset()
3334
{
@@ -36,10 +37,10 @@ public function it_will_not_add_excluded_asset()
3637
$response = $this->middleware->handle($request, $this->getNext('pageWithCssAndJs'), null, null, ['thing']);
3738

3839
$this->assertTrue($this->isServerPushResponse($response));
39-
$this->assertTrue(!str_contains($response->headers, 'thing'));
40+
$this->assertTrue(!Str::contains($response->headers, 'thing'));
4041
$this->assertCount(1, explode(",", $response->headers->get('link')));
4142
}
42-
43+
4344
/** @test */
4445
public function it_will_not_modify_a_response_with_no_server_push_assets()
4546
{
@@ -114,8 +115,8 @@ public function it_will_return_correct_push_headers_for_multiple_assets()
114115
$response = $this->middleware->handle($request, $this->getNext('pageWithCssAndJs'));
115116

116117
$this->assertTrue($this->isServerPushResponse($response));
117-
$this->assertTrue(str_contains($response->headers, 'style'));
118-
$this->assertTrue(str_contains($response->headers, 'script'));
118+
$this->assertTrue(Str::contains($response->headers, 'style'));
119+
$this->assertTrue(Str::contains($response->headers, 'script'));
119120
$this->assertCount(2, explode(",", $response->headers->get('link')));
120121
}
121122

0 commit comments

Comments
 (0)