3333 * @method bool writeElement(string $name, string $content = null)
3434 * @method bool writeRaw(string $content)
3535 */
36- class XMLWriter
36+ class XMLWriter extends \XMLWriter
3737{
3838 /** Temporary storage method */
3939 const STORAGE_MEMORY = 1 ;
4040 const STORAGE_DISK = 2 ;
4141
42- /**
43- * Internal XMLWriter
44- *
45- * @var \XMLWriter
46- */
47- private $ xmlWriter ;
48-
4942 /**
5043 * Temporary filename
5144 *
@@ -61,26 +54,23 @@ class XMLWriter
6154 */
6255 public function __construct ($ pTemporaryStorage = self ::STORAGE_MEMORY , $ pTemporaryStorageDir = './ ' , $ compatibility = false )
6356 {
64- // Create internal XMLWriter
65- $ this ->xmlWriter = new \XMLWriter ();
66-
6757 // Open temporary storage
6858 if ($ pTemporaryStorage == self ::STORAGE_MEMORY ) {
69- $ this ->xmlWriter -> openMemory ();
59+ $ this ->openMemory ();
7060 } else {
7161 // Create temporary filename
7262 $ this ->tempFileName = @tempnam ($ pTemporaryStorageDir , 'xml ' );
7363
7464 // Open storage
75- $ this ->xmlWriter -> openUri ($ this ->tempFileName );
65+ $ this ->openUri ($ this ->tempFileName );
7666 }
7767
7868 if ($ compatibility ) {
79- $ this ->xmlWriter -> setIndent (false );
80- $ this ->xmlWriter -> setIndentString ('' );
69+ $ this ->setIndent (false );
70+ $ this ->setIndentString ('' );
8171 } else {
82- $ this ->xmlWriter -> setIndent (true );
83- $ this ->xmlWriter -> setIndentString (' ' );
72+ $ this ->setIndent (true );
73+ $ this ->setIndentString (' ' );
8474 }
8575 }
8676
@@ -89,9 +79,6 @@ public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTempora
8979 */
9080 public function __destruct ()
9181 {
92- // Desctruct XMLWriter
93- unset($ this ->xmlWriter );
94-
9582 // Unlink temporary files
9683 if ($ this ->tempFileName != '' ) {
9784 if (@unlink ($ this ->tempFileName ) === false ) {
@@ -100,23 +87,6 @@ public function __destruct()
10087 }
10188 }
10289
103- /**
104- * Catch function calls (and pass them to internal XMLWriter)
105- *
106- * @param mixed $function
107- * @param mixed $args
108- */
109- public function __call ($ function , $ args )
110- {
111- try {
112- if (@call_user_func_array (array ($ this ->xmlWriter , $ function ), $ args ) === false ) {
113- throw new \Exception ('The method ' .$ function .' doesn \'t exist. ' );
114- }
115- } catch (\Exception $ ex ) {
116- // Do nothing!
117- }
118- }
119-
12090 /**
12191 * Get written data
12292 *
@@ -125,9 +95,9 @@ public function __call($function, $args)
12595 public function getData ()
12696 {
12797 if ($ this ->tempFileName == '' ) {
128- return $ this ->xmlWriter -> outputMemory (true );
98+ return $ this ->outputMemory (true );
12999 } else {
130- $ this ->xmlWriter -> flush ();
100+ $ this ->flush ();
131101 return file_get_contents ($ this ->tempFileName );
132102 }
133103 }
@@ -147,14 +117,14 @@ public function getData()
147117 */
148118 public function writeElementBlock ($ element , $ attributes , $ value = null )
149119 {
150- $ this ->xmlWriter -> startElement ($ element );
120+ $ this ->startElement ($ element );
151121 if (!is_array ($ attributes )) {
152122 $ attributes = array ($ attributes => $ value );
153123 }
154124 foreach ($ attributes as $ attribute => $ value ) {
155- $ this ->xmlWriter -> writeAttribute ($ attribute , $ value );
125+ $ this ->writeAttribute ($ attribute , $ value );
156126 }
157- $ this ->xmlWriter -> endElement ();
127+ $ this ->endElement ();
158128 }
159129
160130 /**
@@ -170,11 +140,11 @@ public function writeElementIf($condition, $element, $attribute = null, $value =
170140 {
171141 if ($ condition == true ) {
172142 if (is_null ($ attribute )) {
173- $ this ->xmlWriter -> writeElement ($ element , $ value );
143+ $ this ->writeElement ($ element , $ value );
174144 } else {
175- $ this ->xmlWriter -> startElement ($ element );
176- $ this ->xmlWriter -> writeAttribute ($ attribute , $ value );
177- $ this ->xmlWriter -> endElement ();
145+ $ this ->startElement ($ element );
146+ $ this ->writeAttribute ($ attribute , $ value );
147+ $ this ->endElement ();
178148 }
179149 }
180150 }
@@ -190,7 +160,7 @@ public function writeElementIf($condition, $element, $attribute = null, $value =
190160 public function writeAttributeIf ($ condition , $ attribute , $ value )
191161 {
192162 if ($ condition == true ) {
193- $ this ->xmlWriter -> writeAttribute ($ attribute , $ value );
163+ $ this ->writeAttribute ($ attribute , $ value );
194164 }
195165 }
196166}
0 commit comments