| Conditions | 4 |
| Paths | 4 |
| Total Lines | 27 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 43 | public function determineActiveForUrl(string $url, string $root = '/') |
||
| 44 | { |
||
| 45 | $itemUrl = Url::fromString($this->url); |
||
| 46 | $matchUrl = Url::fromString($url); |
||
| 47 | |||
| 48 | // If the hosts don't match, this url isn't active. |
||
| 49 | if ($itemUrl->getHost() !== $matchUrl->getHost()) { |
||
| 50 | return $this->setInactive(); |
||
| 51 | } |
||
| 52 | |||
| 53 | // If this url doesn't start with the root, it's inactive. |
||
| 54 | if (! Str::startsWith($itemUrl->getPath(), $root)) { |
||
| 55 | return $this->setInactive(); |
||
| 56 | } |
||
| 57 | |||
| 58 | // For the next comparisons we just need the paths, and we'll remove |
||
| 59 | // the root first. |
||
| 60 | $itemPath = Str::removeFromStart($root, $itemUrl->getPath()); |
||
| 61 | $matchPath = Str::removeFromStart($root, $matchUrl->getPath()); |
||
| 62 | |||
| 63 | // If this url starts with the url we're matching with, it's active. |
||
| 64 | if (Str::startsWith($matchPath, $itemPath)) { |
||
| 65 | return $this->setActive(); |
||
| 66 | } |
||
| 67 | |||
| 68 | return $this->setInactive(); |
||
| 69 | } |
||
| 70 | } |
||
| 71 |