These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\View\Strategy; |
||
12 | |||
13 | use WebinoDraw\Dom\Document; |
||
14 | use WebinoDraw\Event\AjaxEvent; |
||
15 | use Zend\EventManager\EventManagerAwareInterface; |
||
16 | use Zend\EventManager\EventManagerAwareTrait; |
||
17 | use Zend\View\ViewEvent; |
||
18 | |||
19 | /** |
||
20 | * Draw matched containers and return the JSON XHTML of matched fragments |
||
21 | */ |
||
22 | abstract class AbstractDrawAjaxStrategy extends AbstractDrawStrategy implements EventManagerAwareInterface |
||
23 | { |
||
24 | use EventManagerAwareTrait; |
||
25 | |||
26 | /** |
||
27 | * @var AjaxEvent |
||
28 | */ |
||
29 | protected $event; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $eventIdentifier = 'WebinoDraw'; |
||
35 | |||
36 | /** |
||
37 | * @return AjaxEvent |
||
38 | */ |
||
39 | public function getEvent() |
||
40 | { |
||
41 | if (null === $this->event) { |
||
42 | $this->setEvent(new AjaxEvent); |
||
43 | } |
||
44 | return $this->event; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @param AjaxEvent $event |
||
49 | */ |
||
50 | public function setEvent(AjaxEvent $event) |
||
51 | { |
||
52 | $this->event = $event; |
||
53 | return $this; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Return XHTML of nodes matched by XPath |
||
58 | * |
||
59 | * @param Document $dom |
||
60 | * @param string $xpath |
||
61 | * @return string XHTML |
||
62 | */ |
||
63 | public function createContainer(Document $dom, $xpath) |
||
64 | { |
||
65 | $code = ''; |
||
66 | foreach ($dom->getXpath()->query($xpath) as $node) { |
||
67 | if (!empty($node)) { |
||
68 | $code.= $dom->saveHTML($node); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | return $code; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @param ViewEvent $event |
||
77 | */ |
||
78 | public function injectResponse(ViewEvent $event) |
||
79 | { |
||
80 | if (!$this->shouldRespond($event)) { |
||
81 | return; |
||
82 | } |
||
83 | |||
84 | /* @var $response \Zend\Http\Response */ |
||
85 | $response = $event->getResponse(); |
||
86 | $options = $this->draw->getOptions(); |
||
87 | |||
88 | $dom = $this->draw->createDom( |
||
89 | $this->createContainer( |
||
90 | $this->draw->createDom($response->getBody()), |
||
91 | $options->getAjaxContainerXpath() |
||
92 | ) |
||
93 | ); |
||
94 | |||
95 | $this->draw->drawDom( |
||
96 | $dom->getDocumentElement(), |
||
97 | $options->getInstructions(), |
||
98 | $this->collectModelVariables($event->getModel()) |
||
0 ignored issues
–
show
|
|||
99 | ); |
||
100 | |||
101 | $response->setContent($this->respond($dom, $options->getAjaxFragmentXpath())); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @param Document $dom |
||
106 | * @param string $xpath |
||
107 | * @return \WebinoDraw\Ajax\Json |
||
108 | */ |
||
109 | abstract protected function respond(Document $dom, $xpath); |
||
110 | } |
||
111 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: