From 72ff083177396e50fa941d7b530c98a058da4950 Mon Sep 17 00:00:00 2001
From: Phil Lello <philipl@catalyst-eu.net>
Date: Fri, 4 Apr 2014 12:57:44 +0100
Subject: [PATCH] lib/filestorage/stored_file.php: Added get_xml_domdocument
 method

This patch returns a DOMDocument directly from stored content, to
avoid reading a file into memory then creating DOMDocument from a
string. This is much more resource friendly.
---
 lib/filestorage/stored_file.php |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/lib/filestorage/stored_file.php b/lib/filestorage/stored_file.php
index 1910392..d8f9245 100644
--- a/lib/filestorage/stored_file.php
+++ b/lib/filestorage/stored_file.php
@@ -460,6 +460,26 @@ class stored_file {
     }
 
     /**
+     * Returns file content as a DOMDocument
+     *
+     * @param int $options Bitwise OR of the libxml option constants
+     * @return DOMDocument content
+     */
+    public function get_xml_domdocument($options = 0) {
+        $path = $this->get_content_file_location();
+        if (!is_readable($path)) {
+            if (!$this->fs->try_content_recovery($this) or !is_readable($path)) {
+                throw new file_exception('storedfilecannotread', '', $path);
+            }
+        }
+        $doc = new DOMDocument();
+        if ($doc->load($this->get_content_file_location(), $options) == FALSE) {
+            $doc = false;
+        }
+        return $doc;
+    }
+
+    /**
      * Copy content of file to given pathname.
      *
      * @param string $pathname real path to the new file
-- 
1.7.9.5

