1 | <?php |
||
48 | class XmlFile |
||
49 | { |
||
50 | /** |
||
51 | * Path to XML file |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $path; |
||
55 | |||
56 | /** |
||
57 | * Root SimpleXML node |
||
58 | * @var SimpleXMLElement |
||
59 | */ |
||
60 | protected $xml; |
||
61 | |||
62 | /** |
||
63 | * Constructor |
||
64 | * |
||
65 | * @param string $filePath Path to XML file |
||
66 | * |
||
67 | * @throws \InvalidArgumentException if path links to a directory |
||
68 | * @return void |
||
|
|||
69 | */ |
||
70 | 20 | public function __construct($filePath) |
|
84 | |||
85 | /** |
||
86 | * Tells if the file exists |
||
87 | * |
||
88 | * @return boolean |
||
89 | */ |
||
90 | 19 | public function exists() |
|
94 | |||
95 | /** |
||
96 | * Try to return the real path of the file. If not possible, |
||
97 | * returns user-submitted path (@see __construct) |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | 19 | public function getRealPath() |
|
107 | |||
108 | /** |
||
109 | * Tells if the file is readable |
||
110 | * |
||
111 | * @return boolean |
||
112 | */ |
||
113 | 16 | public function isReadable() |
|
117 | |||
118 | /** |
||
119 | * Opens the XML file (if not already done) and return the SimpleXML root |
||
120 | * node. |
||
121 | * |
||
122 | * @throws Exceptions\FileNotFoundException If file not found/readable |
||
123 | * @throws Exceptions\XmlErrorException If XML errors were found (libxml) |
||
124 | * @return SimpleXMLElement |
||
125 | */ |
||
126 | 16 | public function open() |
|
148 | |||
149 | /** |
||
150 | * Returns the contents of the XML file |
||
151 | * |
||
152 | * @return string |
||
153 | */ |
||
154 | 1 | public function __toString() |
|
158 | |||
159 | /** |
||
160 | * SimpleXML wrapper to access XML nodes the simple way: $file->node->name |
||
161 | * |
||
162 | * @param string $var XML node name |
||
163 | * |
||
164 | * @return mixed |
||
165 | */ |
||
166 | 1 | public function __get($var) |
|
170 | |||
171 | /** |
||
172 | * SimpleXML wrapper to do a Xpath query on the file. |
||
173 | * |
||
174 | * @param string $path Path to XML node |
||
175 | * |
||
176 | * @return mixed |
||
177 | */ |
||
178 | 12 | public function xpath($path) |
|
182 | } |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.