|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Webino (http://webino.sk) |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/webino/WebinoDraw for the canonical source repository |
|
6
|
|
|
* @copyright Copyright (c) 2012-2017 Webino, s. r. o. (http://webino.sk) |
|
7
|
|
|
* @author Peter Bačinský <[email protected]> |
|
8
|
|
|
* @license BSD-3-Clause |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace WebinoDraw\Event; |
|
12
|
|
|
|
|
13
|
|
|
use WebinoDraw\Ajax\FragmentXpath; |
|
14
|
|
|
use WebinoDraw\Ajax\Json; |
|
15
|
|
|
use WebinoDraw\Exception\UnexpectedValueException; |
|
16
|
|
|
use Zend\EventManager\Event; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class AjaxEvent |
|
20
|
|
|
*/ |
|
21
|
|
|
class AjaxEvent extends Event |
|
22
|
|
|
{ |
|
23
|
|
|
/**#@+ |
|
24
|
|
|
* Ajax events |
|
25
|
|
|
*/ |
|
26
|
|
|
const EVENT_AJAX = 'ajax'; |
|
27
|
|
|
/**#@-*/ |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var Json |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $json; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var FragmentXpath |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $fragmentXpath; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return Json |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getJson() |
|
43
|
|
|
{ |
|
44
|
|
|
if (null === $this->json) { |
|
45
|
|
|
$this->setJson(new Json); |
|
46
|
|
|
} |
|
47
|
|
|
return $this->json; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param array|Json $json |
|
52
|
|
|
* @return $this |
|
53
|
|
|
*/ |
|
54
|
|
|
public function setJson($json) |
|
55
|
|
|
{ |
|
56
|
|
|
if (is_array($json)) { |
|
57
|
|
|
$this->json = $this->getJson(); |
|
58
|
|
|
$this->setParam('json', $this->json); |
|
59
|
|
|
$this->json->merge($json); |
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if ($json instanceof Json) { |
|
64
|
|
|
$this->setParam('json', $json); |
|
65
|
|
|
$this->json = $json; |
|
66
|
|
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
throw new UnexpectedValueException('Expected array|Json'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return FragmentXpath |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getFragmentXpath() |
|
76
|
|
|
{ |
|
77
|
|
|
if (null === $this->fragmentXpath) { |
|
78
|
|
|
$this->setFragmentXpath(new FragmentXpath); |
|
79
|
|
|
} |
|
80
|
|
|
return $this->fragmentXpath; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param string|FragmentXpath $xpath |
|
85
|
|
|
* @return $this |
|
86
|
|
|
*/ |
|
87
|
|
|
public function setFragmentXpath($xpath) |
|
88
|
|
|
{ |
|
89
|
|
|
if (is_string($xpath)) { |
|
90
|
|
|
$this->fragmentXpath = $this->getFragmentXpath(); |
|
91
|
|
|
$this->setParam('fragmentXpath', $this->fragmentXpath); |
|
92
|
|
|
$this->fragmentXpath->set($xpath); |
|
93
|
|
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
if ($xpath instanceof FragmentXpath) { |
|
97
|
|
|
$this->setParam('fragmentXpath', $xpath); |
|
98
|
|
|
$this->fragmentXpath = $xpath; |
|
99
|
|
|
return $this; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
throw new UnexpectedValueException('Expected string|FragmentXpath'); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|