Skip to content

Commit aaf5fb5

Browse files
committed
Adds support for format
Adds magic function to string for URL Builder
1 parent ba12408 commit aaf5fb5

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/UrlBuilder.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,23 @@ public function setExtract($left, $top, $width, $height)
9393
return $this;
9494
}
9595

96+
public function setFormat($format)
97+
{
98+
$this->params['format'] = $format;
99+
100+
return $this;
101+
}
102+
96103
public function createURL()
97104
{
98105
$query = new UrlHelper($this->path, $this->params, $this->secret);
99106

100107
return 'https://' . $this->domain . $query;
101108
}
102109

110+
public function __toString()
111+
{
112+
return $this->createURL();
113+
}
114+
103115
}

tests/src/UrlTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,17 @@ public function testUnsignedURL()
6363
$this->assertEquals($expected, $url);
6464
}
6565

66+
public function testToString()
67+
{
68+
69+
$urlBuilder = $this->urlBuilder = new UrlBuilder('image.barnebys.sh');
70+
$urlBuilder->setPath('https://dummyimage.com/600x400/000/fff');
71+
72+
73+
$url = (string) $urlBuilder;
74+
$expected = 'https://image.barnebys.sh/https%3A%2F%2Fdummyimage.com%2F600x400%2F000%2Ffff';
75+
76+
$this->assertEquals($expected, $url);
77+
}
78+
6679
}

0 commit comments

Comments
 (0)