55namespace WsdlToPhp \WsdlHandler \Tag ;
66
77use DOMElement ;
8- use WsdlToPhp \DomHandler \NodeHandler ;
9- use WsdlToPhp \WsdlHandler \AbstractDocument ;
108use WsdlToPhp \DomHandler \AbstractAttributeHandler as Attribute ;
11- use WsdlToPhp \DomHandler \ElementHandler ;
129use WsdlToPhp \DomHandler \AbstractNodeHandler ;
10+ use WsdlToPhp \DomHandler \ElementHandler ;
11+ use WsdlToPhp \DomHandler \NodeHandler ;
12+ use WsdlToPhp \WsdlHandler \AbstractDocument ;
1313
1414abstract class AbstractTag extends ElementHandler
1515{
1616 const MAX_DEEP = 5 ;
1717
1818 /**
19- * This method aims to get the parent element that matches a valid Wsdl element (aka struct)
20- * @param bool $checkName
21- * @param array $additionalTags
22- * @param int $maxDeep
23- * @param bool $strict
24- * @return NodeHandler|null
19+ * This method aims to get the parent element that matches a valid Wsdl element (aka struct).
20+ *
21+ * @return null|NodeHandler
2522 */
2623 public function getSuitableParent (bool $ checkName = true , array $ additionalTags = [], int $ maxDeep = self ::MAX_DEEP , bool $ strict = false ): ?AbstractNodeHandler
2724 {
2825 $ parentNode = null ;
2926 if ($ this ->getParent () instanceof AbstractNodeHandler) {
3027 $ parentTags = $ strict ? $ additionalTags : $ this ->getSuitableParentTags ($ additionalTags );
3128 $ parentNode = $ this ->getParent ()->getNode ();
32- while ($ maxDeep -- > 0 && ($ parentNode instanceof DOMElement) && !empty ($ parentNode ->nodeName ) && (!preg_match ('/ ' . implode ('| ' , $ parentTags ) . '/i ' , $ parentNode ->nodeName ) || ($ checkName && preg_match ('/ ' . implode ('| ' , $ parentTags ) . '/i ' , $ parentNode ->nodeName ) && (!$ parentNode ->hasAttribute ('name ' ) || $ parentNode ->getAttribute ('name ' ) === '' )))) {
29+ while ($ maxDeep -- > 0 && ($ parentNode instanceof DOMElement) && !empty ($ parentNode ->nodeName ) && (!preg_match ('/ ' . implode ('| ' , $ parentTags ). '/i ' , $ parentNode ->nodeName ) || ($ checkName && preg_match ('/ ' . implode ('| ' , $ parentTags ). '/i ' , $ parentNode ->nodeName ) && (!$ parentNode ->hasAttribute ('name ' ) || '' === $ parentNode ->getAttribute ('name ' ))))) {
3330 $ parentNode = $ parentNode ->parentNode ;
3431 }
3532 if ($ parentNode instanceof DOMElement) {
@@ -42,29 +39,6 @@ public function getSuitableParent(bool $checkName = true, array $additionalTags
4239 return $ parentNode ;
4340 }
4441
45- protected function getSuitableParentTags (array $ additionalTags = []): array
46- {
47- return array_merge ([
48- AbstractDocument::TAG_ELEMENT ,
49- AbstractDocument::TAG_ATTRIBUTE ,
50- AbstractDocument::TAG_SIMPLE_TYPE ,
51- AbstractDocument::TAG_COMPLEX_TYPE ,
52- ], $ additionalTags );
53- }
54-
55- protected function getStrictParent (string $ name , bool $ checkName = false ): ?AbstractNodeHandler
56- {
57- $ parent = $ this ->getSuitableParent ($ checkName , [
58- $ name ,
59- ], self ::MAX_DEEP , true );
60-
61- if ($ parent instanceof AbstractNodeHandler && $ parent ->getName () === $ name ) {
62- return $ parent ;
63- }
64-
65- return null ;
66- }
67-
6842 public function hasAttributeName (): bool
6943 {
7044 return $ this ->hasAttribute (Attribute::ATTRIBUTE_NAME );
@@ -94,4 +68,27 @@ public function getValueAttributeValue(bool $withNamespace = false, bool $within
9468 {
9569 return $ this ->getAttribute (Attribute::ATTRIBUTE_VALUE ) instanceof Attribute ? $ this ->getAttribute (Attribute::ATTRIBUTE_VALUE )->getValue ($ withNamespace , $ withinItsType , $ asType ) : '' ;
9670 }
71+
72+ protected function getSuitableParentTags (array $ additionalTags = []): array
73+ {
74+ return array_merge ([
75+ AbstractDocument::TAG_ELEMENT ,
76+ AbstractDocument::TAG_ATTRIBUTE ,
77+ AbstractDocument::TAG_SIMPLE_TYPE ,
78+ AbstractDocument::TAG_COMPLEX_TYPE ,
79+ ], $ additionalTags );
80+ }
81+
82+ protected function getStrictParent (string $ name , bool $ checkName = false ): ?AbstractNodeHandler
83+ {
84+ $ parent = $ this ->getSuitableParent ($ checkName , [
85+ $ name ,
86+ ], self ::MAX_DEEP , true );
87+
88+ if ($ parent instanceof AbstractNodeHandler && $ parent ->getName () === $ name ) {
89+ return $ parent ;
90+ }
91+
92+ return null ;
93+ }
9794}
0 commit comments