AbstractResponsePlugin   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
dl 0
loc 50
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A _init() 0 5 1
A response() 0 3 1
A init() 0 2 1
A addCommand() 0 5 1
1
<?php
2
3
/**
4
 * AbstractResponsePlugin.php
5
 *
6
 * Interface for Jaxon Response plugins.
7
 *
8
 * A response plugin provides additional services not already provided by the
9
 * <Jaxon\Response\Response> class with regard to sending response commands to the client.
10
 * In addition, a response command may send javascript to the browser at page load
11
 * to aid in the processing of its response commands.
12
 *
13
 * @package jaxon-core
14
 * @author Jared White
15
 * @author J. Max Wilson
16
 * @author Joseph Woolley
17
 * @author Steffen Konerow
18
 * @author Thierry Feuzeu <[email protected]>
19
 * @copyright Copyright (c) 2005-2007 by Jared White & J. Max Wilson
20
 * @copyright Copyright (c) 2008-2010 by Joseph Woolley, Steffen Konerow, Jared White  & J. Max Wilson
21
 * @copyright 2016 Thierry Feuzeu <[email protected]>
22
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
23
 * @link https://github.com/jaxon-php/jaxon-core
24
 */
25
26
namespace Jaxon\Plugin;
27
28
use Jaxon\Script\JqCall;
29
use Jaxon\Plugin\Response\DataBag\DataBagContext;
30
use Jaxon\Response\AbstractResponse;
31
use Jaxon\Response\Command;
32
use JsonSerializable;
33
34
/**
35
 * @method JqCall jq(string $sPath = '', $xContext = null)
36
 * @method DataBagContext bag(string $sName)
37
 */
38
abstract class AbstractResponsePlugin extends AbstractPlugin implements ResponsePluginInterface
39
{
40
    /**
41
     * The object used to build the response that will be sent to the client browser
42
     *
43
     * @var AbstractResponse
44
     */
45
    private $xResponse = null;
46
47
    /**
48
     * Initialize the plugin
49
     *
50
     * @return void
51
     */
52
    protected function init()
53
    {}
54
55
    /**
56
     * @param AbstractResponse $xResponse   The response
57
     *
58
     * @return self
59
     */
60
    public function _init(AbstractResponse $xResponse): self
61
    {
62
        $this->xResponse = $xResponse;
63
        $this->init();
64
        return $this;
65
    }
66
67
    /**
68
     * @inheritDoc
69
     */
70
    public function response(): ?AbstractResponse
71
    {
72
        return $this->xResponse;
73
    }
74
75
    /**
76
     * Add a plugin command to the response
77
     *
78
     * @param string $sName    The command name
79
     * @param array|JsonSerializable $aOptions    The command options
80
     *
81
     * @return Command
82
     */
83
    public function addCommand(string $sName, array|JsonSerializable $aOptions): Command
84
    {
85
        return $this->xResponse
86
            ->addCommand($sName, $aOptions)
87
            ->setOption('plugin', $this->getName());
88
    }
89
}
90