1 | <?php |
||
5 | abstract class AbstractElementHandler extends AbstractNodeHandler |
||
6 | { |
||
7 | /** |
||
8 | * @param \DOMElement $element |
||
9 | * @param AbstractDomDocumentHandler $domDocument |
||
10 | * @param int $index |
||
11 | */ |
||
12 | 584 | public function __construct(\DOMElement $element, AbstractDomDocumentHandler $domDocument, $index = -1) |
|
16 | /** |
||
17 | * @see \WsdlToPhp\PackageGenerator\DomHandler\AbstractNodeHandler::getNode() |
||
18 | * @return \DOMElement |
||
19 | */ |
||
20 | 548 | public function getNode() |
|
24 | /** |
||
25 | * Alias to getNode() |
||
26 | * @return \DOMElement |
||
27 | */ |
||
28 | 512 | public function getElement() |
|
32 | /** |
||
33 | * @param string $name |
||
34 | * @return boolean |
||
35 | */ |
||
36 | 504 | public function hasAttribute($name) |
|
40 | /** |
||
41 | * @param string $name |
||
42 | * @return AttributeHandler|null |
||
43 | */ |
||
44 | 500 | public function getAttribute($name) |
|
48 | /** |
||
49 | * @param string $name |
||
50 | * @return mixed |
||
51 | */ |
||
52 | 52 | public function getAttributeValue($name, $withNamespace = false, $withinItsType = true, $asType = AbstractAttributeHandler::DEFAULT_VALUE_TYPE) |
|
61 | /** |
||
62 | * @param string $name |
||
63 | * @return NodeHandler[]|ElementHandler[] |
||
64 | */ |
||
65 | 264 | public function getChildrenByName($name) |
|
75 | /** |
||
76 | * @return ElementHandler[] |
||
77 | */ |
||
78 | 92 | public function getElementChildren() |
|
86 | /** |
||
87 | * @param string $name |
||
88 | * @param array $attributes |
||
89 | * @return ElementHandler[] |
||
90 | */ |
||
91 | 76 | public function getChildrenByNameAndAttributes($name, array $attributes) |
|
95 | /** |
||
96 | * @param string $name |
||
97 | * @param array $attributes |
||
98 | * @return ElementHandler|null |
||
99 | */ |
||
100 | 76 | public function getChildByNameAndAttributes($name, array $attributes) |
|
105 | /** |
||
106 | * Info at {@link https://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints} |
||
107 | * @return int |
||
108 | */ |
||
109 | 16 | public function getMaxOccurs() |
|
120 | /** |
||
121 | * Info at {@link https://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints} |
||
122 | * @return int |
||
123 | */ |
||
124 | 32 | public function getMinOccurs() |
|
132 | /** |
||
133 | * Info at {@link https://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints} |
||
134 | * @return bool |
||
135 | */ |
||
136 | 4 | public function canOccurSeveralTimes() |
|
140 | /** |
||
141 | * Info at {@link https://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints} |
||
142 | * @return bool |
||
143 | */ |
||
144 | 8 | public function canOccurOnlyOnce() |
|
148 | /** |
||
149 | * Info at {@link https://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints} |
||
150 | * @return bool |
||
151 | */ |
||
152 | 4 | public function isOptional() |
|
156 | /** |
||
157 | * Info at {@link https://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints} |
||
158 | * @return bool |
||
159 | */ |
||
160 | 8 | public function isRequired() |
|
164 | } |
||
165 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.