| Total Complexity | 13 |
| Total Lines | 86 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class DataBagPlugin extends \Jaxon\Plugin\Response |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var Bag |
||
| 13 | */ |
||
| 14 | protected $xBag; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * The constructor |
||
| 18 | */ |
||
| 19 | public function __construct() |
||
| 20 | { |
||
| 21 | $aData = isset($_POST['jxnbags']) ? $this->readData($_POST) : |
||
| 22 | (isset($_GET['jxnbags']) ? $this->readData($_GET) : []); |
||
| 23 | $this->xBag = new Bag($aData); |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param array $aFrom |
||
| 28 | * |
||
| 29 | * @return array |
||
| 30 | */ |
||
| 31 | private function readData(array $aFrom): array |
||
| 32 | { |
||
| 33 | // Todo: clean input data. |
||
| 34 | if(is_string($aFrom['jxnbags'])) |
||
| 35 | { |
||
| 36 | return json_decode($aFrom['jxnbags'], true) ?: []; |
||
| 37 | } |
||
| 38 | if(is_array($aFrom['jxnbags'])) |
||
| 39 | { |
||
| 40 | return $aFrom['jxnbags']; |
||
| 41 | } |
||
| 42 | return []; |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @inheritDoc |
||
| 47 | */ |
||
| 48 | public function getName(): string |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @inheritDoc |
||
| 55 | */ |
||
| 56 | public function getHash(): string |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @inheritDoc |
||
| 64 | */ |
||
| 65 | public function getReadyScript(): string |
||
| 66 | { |
||
| 67 | return ' |
||
| 68 | jaxon.command.handler.register("bags.set", function(args) { |
||
| 69 | for (const bag in args.data) { |
||
| 70 | jaxon.ajax.parameters.bags[bag] = args.data[bag]; |
||
| 71 | } |
||
| 72 | }); |
||
| 73 | '; |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @return void |
||
| 78 | */ |
||
| 79 | public function writeCommand() |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @param string $sName |
||
| 89 | * |
||
| 90 | * @return Context |
||
| 91 | */ |
||
| 92 | public function bag(string $sName): Context |
||
| 97 |