| 1 | <?php |
||
| 9 | abstract class Base extends BaseContext implements ContextInterface |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var Url |
||
| 13 | */ |
||
| 14 | protected $url; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * {@inheritdoc} |
||
| 18 | */ |
||
| 19 | 1 | public function getUrl() |
|
| 20 | { |
||
| 21 | 1 | if (!$this->url) { |
|
| 22 | 1 | $this->url = new Url($this->getUrlParts()); |
|
| 23 | 1 | } |
|
| 24 | |||
| 25 | 1 | return $this->url; |
|
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Extracts the url information from the current class name and |
||
| 30 | * namespace |
||
| 31 | * |
||
| 32 | * @return array |
||
| 33 | */ |
||
| 34 | 1 | protected function getUrlParts() |
|
| 35 | { |
||
| 36 | 1 | $path = array_map( |
|
| 37 | 1 | 'strtolower', |
|
| 38 | 1 | array_slice(preg_split('@\\\\|_@', static::class), -3) |
|
| 39 | 1 | ); |
|
| 40 | |||
| 41 | 1 | return ['httpMethod' => $this->getHttpMethod(), 'path' => $path]; |
|
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Get the http method specific for the context |
||
| 46 | * |
||
| 47 | * @return string |
||
| 48 | */ |
||
| 49 | abstract public function getHttpMethod(); |
||
| 50 | } |
||
| 51 |