Absolute.php
38 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Asset\Location; |
| 4 | |
| 5 | use AC\Asset\Location; |
| 6 | |
| 7 | final class Absolute implements Location |
| 8 | { |
| 9 | |
| 10 | private string $url; |
| 11 | |
| 12 | private string $path; |
| 13 | |
| 14 | public function __construct(string $url, string $path) |
| 15 | { |
| 16 | $this->url = rtrim($url, '/'); |
| 17 | $this->path = rtrim($path, '/'); |
| 18 | } |
| 19 | |
| 20 | public function with_suffix(string $suffix): self |
| 21 | { |
| 22 | $url = $this->get_url() . '/' . ltrim($suffix, '/'); |
| 23 | $path = $this->get_path() . '/' . ltrim($suffix, '/'); |
| 24 | |
| 25 | return new self($url, $path); |
| 26 | } |
| 27 | |
| 28 | public function get_url(): string |
| 29 | { |
| 30 | return $this->url; |
| 31 | } |
| 32 | |
| 33 | public function get_path(): string |
| 34 | { |
| 35 | return $this->path; |
| 36 | } |
| 37 | |
| 38 | } |