Ejemplo n.º 1
0
 /**
  *  INSTANTIATE DOMDocument
  *  create or set a new Domdocument based upon a string or an already declared object
  **/
 private static function _domxpath($path = false, $obj = false, $force = false, $create = false)
 {
     self::$_LDD = false;
     // check that DomDocument and DomXPath are available
     // we don't need to send an error since the Core::library will handle that.
     if (!class_exists('DomDocument') || !class_exists('DOMXPath')) {
         die;
     }
     // return if $_DOM is already declared and we're not forcing re-instantiation.
     if (self::$_DOM instanceof DomDocument && !$force) {
         return self::$_DOM;
     }
     // if no object is specified, instantiate a new one.
     if (!$obj) {
         self::$_DOM = new DomDocument(self::$_VER, self::$_CHR);
         self::$_DOM->preserveWhiteSpace = self::$_PWS;
         self::$_DOM->formatOutput = self::$_FOU;
         // if object provided is a valid instance, use it instead.
     } elseif ($obj instanceof DomDocument) {
         self::$_DOM = $obj;
         // we override force, so xpath will be reinstantiated again.
         $force = true;
         // if object isn't dom... show error.
     } else {
         Core::error('VARTYP', 'LIBTIT', array(__CLASS__, 'object', 'DomDocument'));
     }
     // if there's a path set it and load it.
     if ($path) {
         // we make sure the path is set correctly
         $path = self::path($path, $create, 3);
         //  if the specified file doesn't exist, or the file exists
         //  but it doesn't have a root element defined AND the function
         //  needs a file to be created, do so.
         if ($create && (!file_exists($path) || !self::$_DOM->documentElement)) {
             self::$_DOM->appendChild(self::$_DOM->createElement('root'));
             self::save(false, false);
             self::$_LDD = true;
             //  if we're not creating but the file already exists and has content on it, load it.
         } elseif (!$create && file_exists($path) && filesize($path) > 0) {
             self::$_DOM->load($path);
             self::$_LDD = true;
         }
     }
     // instantiate the domxpath object
     if (!self::$_XPT instanceof DOMXPath || $force) {
         self::$_XPT = new DOMXPath(self::$_DOM);
     }
     return self::$_DOM;
 }