Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
Asset | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getContents | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getBase64Url | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Apie\HtmlBuilders\Assets; |
4 | |
5 | use Symfony\Component\Mime\MimeTypes; |
6 | |
7 | final class Asset |
8 | { |
9 | public function __construct(private string $filePath) |
10 | { |
11 | } |
12 | |
13 | public function getContents(): string |
14 | { |
15 | return file_get_contents($this->filePath); |
16 | } |
17 | |
18 | public function getBase64Url(): string |
19 | { |
20 | $mimeTypes = new MimeTypes(); |
21 | $mimeType = $mimeTypes->guessMimeType($this->filePath); |
22 | return 'data:' . $mimeType . ';base64,' . base64_encode($this->getContents()); |
23 | } |
24 | } |