1 | <?php |
||
16 | trait NodeListTrait { |
||
17 | |||
18 | protected $writer = null; |
||
19 | protected $invalidChars = []; |
||
20 | |||
21 | /** |
||
22 | * @param array $list |
||
23 | * @param Writer $writer |
||
24 | */ |
||
25 | 6 | public function __construct( $list = null, $writer = null ) |
|
30 | |||
31 | 6 | public function __call( $name, $args ) |
|
38 | |||
39 | 6 | public function __toString() |
|
40 | { |
||
41 | 6 | $indent = ''; |
|
42 | 6 | if (!is_object( $this->writer ) || $this->writer->indent ) { |
|
43 | 6 | $indent = "\r\n"; // element() will indent each line with whatever indent string is in the writer |
|
44 | } |
||
45 | 6 | return join( $indent, (array) $this ); |
|
46 | } |
||
47 | |||
48 | 6 | protected static function indent( $content, $indent="\t", $newLine="\r\n" ) |
|
57 | |||
58 | 6 | protected function escape( $contents ) { |
|
62 | |||
63 | 6 | protected function parseArgs( $args ) |
|
64 | { |
||
65 | 6 | $attributes = array(); |
|
66 | 6 | $content = ''; |
|
67 | 6 | foreach ($args as $arg ) { |
|
68 | 6 | if (is_string( $arg ) ) { |
|
69 | 6 | $content .= $this->escape($arg); |
|
70 | 6 | } else if (is_array( $arg )) { |
|
71 | 6 | foreach( $arg as $key => $subArg ) { |
|
72 | 6 | if (is_numeric( $key )) { |
|
73 | list( $subattributes, $subcontent ) = $this->parseArgs( $subArg ); |
||
74 | $attributes = array_merge( $attributes, $subattributes); |
||
75 | $content = \arc\xml::raw( $content . $subcontent ); |
||
76 | } else { |
||
77 | 6 | $attributes[ $key ] = $subArg; |
|
78 | } |
||
79 | } |
||
80 | } else { |
||
81 | 6 | $content .= $arg; |
|
82 | } |
||
83 | } |
||
84 | 6 | return [ $attributes, $content ]; |
|
85 | } |
||
86 | |||
87 | 6 | protected function element( $tagName, $attributes, $content ) |
|
88 | { |
||
89 | 6 | $tagName = \arc\xml::name( $tagName ); |
|
90 | 6 | $el = '<' . $tagName; |
|
91 | 6 | $el .= $this->getAttributes( $attributes ); |
|
92 | 6 | if ($this->hasContent( $content )) { |
|
93 | 6 | $el .= '>' . self::indent( $content, $this->writer->indent, $this->writer->newLine ); |
|
94 | 6 | $el .= '</' . $tagName . '>'; |
|
95 | } else { |
||
96 | $el .= '/>'; |
||
97 | } |
||
98 | 6 | return $el; |
|
99 | } |
||
100 | |||
101 | 6 | protected function getAttributes( $attributes ) |
|
102 | { |
||
103 | 6 | $result = ''; |
|
104 | 6 | if (count( $attributes )) { |
|
105 | 6 | foreach ($attributes as $name => $value ) { |
|
106 | 6 | $result .= \arc\xml::attribute( $name, $value ); |
|
107 | } |
||
108 | } |
||
109 | 6 | return $result; |
|
110 | } |
||
111 | |||
112 | 6 | protected function hasContent( $content ) |
|
116 | |||
117 | } |
||
118 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.