1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleXmlReader; |
4
|
|
|
|
5
|
|
|
use DOMNode; |
6
|
|
|
use XMLReader; |
7
|
|
|
|
8
|
|
|
class ExceptionThrowingXMLReader extends XMLReader |
9
|
|
|
{ |
10
|
|
|
public function open($URI, $encoding = null, $options = 0) |
11
|
|
|
{ |
12
|
|
|
return static::ensureSuccess(@parent::open($URI, $encoding, $options), 'open'); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
static protected function ensureSuccess($returnValue, $operation) |
16
|
|
|
{ |
17
|
|
|
if (! $returnValue) { |
18
|
|
|
throw new XmlException("Error while performing XMLReader::$operation"); |
19
|
|
|
} |
20
|
|
|
return $returnValue; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function expand(DOMNode $baseNode = null) |
24
|
|
|
{ |
25
|
|
|
if (null === $baseNode) { |
26
|
|
|
return static::ensureSuccess(@parent::expand(), 'expend'); |
27
|
|
|
} else { |
28
|
|
|
return static::ensureSuccess(@parent::expand($baseNode), 'expend'); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function read() |
33
|
|
|
{ |
34
|
|
|
return static::ensureSuccess(@parent::read(), 'read'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function tryRead() |
38
|
|
|
{ |
39
|
|
|
// We're ignoring any PHP errors, as we are trying to read |
40
|
|
|
return @parent::read(); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function next($localName = null) |
44
|
|
|
{ |
45
|
|
|
if (null === $localName) { |
46
|
|
|
return static::ensureSuccess(@parent::next(), 'next'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return static::ensureSuccess(@parent::next($localName), 'next'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function tryNext($localName = null) |
53
|
|
|
{ |
54
|
|
|
// We're ignoring any PHP errors, as we are trying to fetch the next element |
55
|
|
|
if (null === $localName) { |
56
|
|
|
return @parent::next(); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return @parent::next($localName); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
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.