| Conditions | 3 |
| Paths | 3 |
| Total Lines | 18 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 31 | public function getAssetPath(Request $request, string $asset, bool $throwException = true): string |
||
| 32 | { |
||
| 33 | $finder = new Finder(); |
||
| 34 | |||
| 35 | $assetFound = $finder->in(rtrim($this->publicDir, '/').'/'.ltrim(pathinfo($asset, PATHINFO_DIRNAME), '/')) |
||
| 36 | ->files() |
||
| 37 | ->name(pathinfo($asset, PATHINFO_FILENAME).'.'.pathinfo($asset, PATHINFO_EXTENSION)) |
||
| 38 | ->count(); |
||
| 39 | |||
| 40 | if (0 < $assetFound) { |
||
| 41 | return rtrim($request->getBasePath(), '/').'/'.ltrim($asset, '/'); |
||
| 42 | } |
||
| 43 | |||
| 44 | if ($throwException) { |
||
| 45 | throw new \InvalidArgumentException('The asset "'.$asset.'" could not be found in "'.$this->publicDir.'".'); |
||
| 46 | } |
||
| 47 | |||
| 48 | return ''; |
||
| 49 | } |
||
| 51 |