| 1 | <?php |
||
| 17 | trait UrlUtils |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @return Request |
||
| 21 | */ |
||
| 22 | abstract public function getRequest(); |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Gets the url for provided path |
||
| 26 | * |
||
| 27 | * @param string $path |
||
| 28 | * @return string |
||
| 29 | */ |
||
| 30 | 4 | public function getUrl($path) |
|
| 31 | { |
||
| 32 | 4 | $regExp = '/\/\/|https?:/i'; |
|
| 33 | 4 | if (preg_match($regExp, $path)) { |
|
| 34 | 2 | return $path; |
|
| 35 | } |
||
| 36 | try { |
||
| 37 | 2 | $generated = call_user_func_array( |
|
| 38 | 2 | [$this->getRouterGenerator(), 'generate'], |
|
| 39 | 2 | func_get_args() |
|
| 40 | 2 | ); |
|
| 41 | 2 | } catch (AuraException $caught) { |
|
| 42 | $generated = false; |
||
| 43 | } |
||
| 44 | |||
| 45 | $path = $generated |
||
| 46 | 2 | ? $generated |
|
| 47 | 2 | : $path; |
|
| 48 | 2 | $basePath = rtrim($this->getRequest()->getBasePath(), '/'); |
|
| 49 | 2 | return ("{$basePath}/{$path}"); |
|
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Return Router path generator |
||
| 54 | * |
||
| 55 | * @return \Aura\Router\Generator |
||
| 56 | */ |
||
| 57 | 2 | protected function getRouterGenerator() |
|
| 63 | } |