File tree Expand file tree Collapse file tree 3 files changed +21
-3
lines changed
Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ final class UrlBuilder
1818
1919 private $ params = [];
2020
21- public function __construct ($ domain , $ secret )
21+ public function __construct ($ domain , $ secret = null )
2222 {
2323 $ this ->domain = $ domain ;
2424 $ this ->secret = $ secret ;
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ final class UrlHelper
1414 private $ params ;
1515 private $ secret ;
1616
17- public function __construct ($ path , $ params , $ secret )
17+ public function __construct ($ path , $ params , $ secret = null )
1818 {
1919 $ this ->path = $ path ;
2020 $ this ->params = $ params ;
@@ -29,8 +29,11 @@ private function getQuery()
2929 $ query .= '? ' . http_build_query ($ this ->params );
3030 }
3131
32+ $ signed = "s= " . md5 ($ this ->secret . $ query );
3233
33- return $ query . (count ($ this ->params ) > 0 ? '& ' : '? ' ) . "s= " . md5 ($ this ->secret . $ query );
34+
35+
36+ return $ query . (empty ($ this ->secret ) ? "" : (count ($ this ->params ) > 0 ? '& ' : '? ' ) . $ signed );
3437 }
3538
3639 public function __toString ()
Original file line number Diff line number Diff line change @@ -47,5 +47,20 @@ public function testUrlWithOptions()
4747 $ this ->assertEquals ($ expected , $ url );
4848 }
4949
50+ public function testUnsignedURL ()
51+ {
52+
53+ $ urlBuilder = $ this ->urlBuilder = new UrlBuilder ('image.barnebys.sh ' );
54+ $ urlBuilder
55+ ->setHeight (200 )
56+ ->setWidth (200 )
57+ ->setPath ('https://dummyimage.com/600x400/000/fff ' );
58+
59+
60+ $ url = $ urlBuilder ->createURL ();
61+ $ expected = 'https://image.barnebys.sh/https%3A%2F%2Fdummyimage.com%2F600x400%2F000%2Ffff?h=200&w=200 ' ;
62+
63+ $ this ->assertEquals ($ expected , $ url );
64+ }
5065
5166}
You can’t perform that action at this time.
0 commit comments