AbstractComponent::_initCallable()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 2
1
<?php
2
3
namespace Jaxon\App;
4
5
use Jaxon\Di\Container;
6
use Jaxon\Plugin\Request\CallableClass\CallableClassHelper;
7
use Jaxon\Response\AjaxResponse;
8
use Jaxon\Response\ComponentResponse;
9
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
38
    {
39
        return $this->nodeResponse;
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
67
    {
68
        $this->node()->item($item);
69
        return $this;
70
    }
71
}
72