| Total Complexity | 5 |
| Total Lines | 60 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | abstract class AbstractComponent extends AbstractCallable |
||
| 11 | {
|
||
| 12 | /** |
||
| 13 | * @var ComponentResponse |
||
| 14 | */ |
||
| 15 | protected $nodeResponse = null; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | protected $overrides = ''; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @inheritDoc |
||
| 24 | */ |
||
| 25 | public function _initCallable(Container $di, CallableClassHelper $xHelper) |
||
| 26 | {
|
||
| 27 | $this->xHelper = $xHelper; |
||
| 28 | // Each component must have its own reponse object. |
||
| 29 | // A component can overrides another one. In this case, |
||
| 30 | // its response is attached to the overriden component DOM node. |
||
| 31 | $this->nodeResponse = $di->newComponentResponse($this->rq($this->overrides ?: '')); |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @inheritDoc |
||
| 36 | */ |
||
| 37 | final protected function _response(): AjaxResponse |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Get the component response |
||
| 44 | * |
||
| 45 | * @return ComponentResponse |
||
| 46 | */ |
||
| 47 | final protected function node(): ComponentResponse |
||
| 48 | {
|
||
| 49 | return $this->nodeResponse; |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Set the attached DOM node content with the component HTML code. |
||
| 54 | * |
||
| 55 | * @return AjaxResponse |
||
| 56 | */ |
||
| 57 | abstract public function render(): AjaxResponse; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Set the component item. |
||
| 61 | * |
||
| 62 | * @param string $item |
||
| 63 | * |
||
| 64 | * @return self |
||
| 65 | */ |
||
| 66 | final public function item(string $item): self |
||
| 70 | } |
||
| 71 | } |
||
| 72 |