| 1 | <?php |
||
| 8 | trait BasePathTrait |
||
| 9 | { |
||
| 10 | private $basePath = ''; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Set the basepath used in the request. |
||
| 14 | * |
||
| 15 | * @param string $basePath |
||
| 16 | * |
||
| 17 | * @return self |
||
| 18 | */ |
||
| 19 | public function basePath($basePath) |
||
| 20 | { |
||
| 21 | $this->basePath = $basePath; |
||
| 22 | |||
| 23 | return $this; |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Removes the basepath from a path. |
||
| 28 | * |
||
| 29 | * @param string $path |
||
| 30 | * |
||
| 31 | * @return string |
||
| 32 | */ |
||
| 33 | private function getPath($path) |
||
| 34 | { |
||
| 35 | if ($this->testBasePath($path)) { |
||
| 36 | return substr($path, strlen($this->basePath)) ?: ''; |
||
| 37 | } |
||
| 38 | |||
| 39 | return $path; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Tests the basepath and returns whether the path matches. |
||
| 44 | * |
||
| 45 | * @param string $path |
||
| 46 | * |
||
| 47 | * @return bool |
||
| 48 | */ |
||
| 49 | private function testBasePath($path) |
||
| 57 | } |
||
| 58 |