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 | 3 | public function __construct( $list = null, $writer = null ) |
|
26 | { |
||
27 | 3 | parent::__construct( $list ); |
|
28 | 3 | $this->writer = $writer; |
|
29 | 3 | } |
|
30 | |||
31 | 3 | public function __call( $name, $args ) |
|
32 | { |
||
33 | 3 | $tagName = $name; |
|
34 | 3 | list( $attributes, $content ) = $this->parseArgs( $args ); |
|
35 | 3 | parent::offsetSet( null, $this->element( $tagName, $attributes, $content ) ); |
|
|
|||
36 | 3 | return $this; |
|
37 | } |
||
38 | |||
39 | 3 | public function __toString() |
|
40 | { |
||
41 | 3 | $indent = ''; |
|
42 | 3 | if (!is_object( $this->writer ) || $this->writer->indent ) { |
|
43 | 3 | $indent = "\r\n"; // element() will indent each line with whatever indent string is in the writer |
|
44 | 3 | } |
|
45 | 3 | return join( $indent, (array) $this ); |
|
46 | } |
||
47 | |||
48 | 3 | protected static function indent( $content, $indent="\t", $newLine="\r\n" ) |
|
49 | { |
||
50 | 3 | if ($indent && ( strpos( $content, '<' ) !== false )) { |
|
51 | 3 | $indent = ( is_string( $indent ) ? $indent : "\t" ); |
|
52 | 3 | return $newLine . preg_replace( '/^(\s*[^\<]*)</m', $indent.'$1<', $content ) . $newLine; |
|
53 | } else { |
||
54 | 2 | return $content; |
|
55 | } |
||
56 | } |
||
57 | |||
58 | 3 | protected function escape( $contents ) { |
|
62 | |||
63 | 3 | protected function parseArgs( $args ) |
|
64 | { |
||
65 | 3 | $attributes = array(); |
|
66 | 3 | $content = ''; |
|
86 | |||
87 | 3 | protected function element( $tagName, $attributes, $content ) |
|
100 | |||
101 | 3 | protected function getAttributes( $attributes ) |
|
111 | |||
112 | 3 | 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.