Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
6 / 7 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Assets | |
85.71% |
6 / 7 |
|
50.00% |
1 / 2 |
3.03 | |
0.00% |
0 / 1 |
| __construct | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
2.02 | |||
| image | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Assets; |
| 6 | |
| 7 | use Cosray\Config; |
| 8 | use Cosray\Exception\RuntimeException; |
| 9 | use Cosray\Util\Path; |
| 10 | |
| 11 | class Assets |
| 12 | { |
| 13 | public readonly string $publicDir; |
| 14 | public readonly string $assetsDir; |
| 15 | public readonly string $cacheDir; |
| 16 | |
| 17 | public function __construct( |
| 18 | protected readonly Config $config, |
| 19 | ) { |
| 20 | $publicDir = realpath($config->path->public); |
| 21 | |
| 22 | if ($publicDir === false) { |
| 23 | throw new RuntimeException('Public directory does not exist: ' . $config->path->public); |
| 24 | } |
| 25 | |
| 26 | $this->publicDir = rtrim($publicDir, '\\/'); |
| 27 | |
| 28 | $this->assetsDir = Path::below($this->publicDir, $config->path->assets); |
| 29 | $this->cacheDir = Path::below($this->publicDir, $config->path->cache); |
| 30 | } |
| 31 | |
| 32 | public function image(string $path): Image |
| 33 | { |
| 34 | return new Image($this, $path); |
| 35 | } |
| 36 | } |