1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Sulu. |
5
|
|
|
* |
6
|
|
|
* (c) MASSIVE ART WebServices GmbH |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sulu\Component\DocumentManager\Event; |
13
|
|
|
|
14
|
|
|
use PHPCR\NodeInterface; |
15
|
|
|
use Sulu\Component\DocumentManager\DocumentHelper; |
16
|
|
|
|
17
|
|
|
class PersistEvent extends AbstractMappingEvent |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param NodeInterface |
21
|
|
|
*/ |
22
|
|
|
private $parentNode; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param object $document |
26
|
|
|
* @param string $locale |
27
|
|
|
* @param array $options |
28
|
|
|
*/ |
29
|
|
|
public function __construct($document, $locale, array $options = []) |
30
|
|
|
{ |
31
|
|
|
$this->document = $document; |
32
|
|
|
$this->locale = $locale; |
33
|
|
|
$this->options = $options; |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
public function getDebugMessage() |
40
|
|
|
{ |
41
|
|
|
return sprintf( |
42
|
|
|
'%s p:%s', |
43
|
|
|
parent::getDebugMessage(), |
44
|
|
|
$this->parentNode ? $this->parentNode->getPath() : '<no parent node>' |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param NodeInterface $node |
50
|
|
|
*/ |
51
|
|
|
public function setNode(NodeInterface $node) |
52
|
|
|
{ |
53
|
|
|
$this->node = $node; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param NodeInterface $parentNode |
58
|
|
|
*/ |
59
|
|
|
public function setParentNode(NodeInterface $parentNode) |
60
|
|
|
{ |
61
|
|
|
$this->parentNode = $parentNode; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return NodeInterface |
66
|
|
|
* |
67
|
|
|
* @throws \RuntimeException |
68
|
|
|
*/ |
69
|
|
View Code Duplication |
public function getNode() |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
if (!$this->node) { |
72
|
|
|
throw new \RuntimeException(sprintf( |
73
|
|
|
'Trying to retrieve node when no node has been set. An event ' . |
74
|
|
|
'listener should have set the node when persisting document "%s"', |
75
|
|
|
DocumentHelper::getDebugTitle($this->document) |
76
|
|
|
)); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $this->node; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return NodeInterface |
84
|
|
|
* |
85
|
|
|
* @throws \RuntimeException |
86
|
|
|
*/ |
87
|
|
View Code Duplication |
public function getParentNode() |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
if (!$this->parentNode) { |
90
|
|
|
throw new \RuntimeException(sprintf( |
91
|
|
|
'Trying to retrieve parent node when no parent node has been set. An event ' . |
92
|
|
|
'listener should have set the node when persisting document "%s"', |
93
|
|
|
DocumentHelper::getDebugTitle($this->document) |
94
|
|
|
)); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $this->parentNode; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return bool |
102
|
|
|
*/ |
103
|
|
|
public function hasParentNode() |
104
|
|
|
{ |
105
|
|
|
return $this->parentNode !== null; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..