Example #1
0
 /**
  * This destructor ensures that any resources are properly disposed.
  *
  * @access public
  */
 public function __destruct()
 {
     unset($this->reader);
     unset($this->writer);
     unset($this->pointer);
     unset($this->length);
     if ($this->file->exists()) {
         unlink($this->file);
         unset($this->file);
     }
 }
Example #2
0
 /**
  * This constructor instantiates the class.
  *
  * @access public
  * @param IO\File $file                                     the file to be opened
  * @throws Throwable\FileNotFound\Exception                 indicates the file could not be
  *                                                          opened
  * @throws Throwable\InvalidArgument\Exception              indicates the file is not readable
  */
 public function __construct(IO\File $file)
 {
     if (!$file->exists()) {
         throw new Throwable\FileNotFound\Exception('Unable to open file :file.', array(':file' => $file));
     }
     if (!$file->isReadable()) {
         throw new Throwable\InvalidArgument\Exception('Unable to read from file. File ":file" is not readable.', array(':file' => $file));
     }
     $this->file = $file;
     $this->handle = null;
     $this->open();
 }
Example #3
0
 /**
  * This method returns an instance of the class with the contents of the specified
  * XML file.
  *
  * @access public
  * @static
  * @param IO\File $file                                     the input file stream to be used
  * @return Core\Data\XML                                    an instance of this class
  * @throws Throwable\InvalidArgument\Exception              indicates a data type mismatch
  * @throws Throwable\FileNotFound\Exception                 indicates that the file does not exist
  */
 public static function load(IO\File $file)
 {
     if (!$file->exists()) {
         throw new Throwable\FileNotFound\Exception('Unable to locate file. File ":file" does not exist.', array(':file' => $file));
     }
     $buffer = file_get_contents($file);
     $buffer = preg_replace('/^' . pack('H*', 'EFBBBF') . '/', '', $buffer);
     if (!preg_match('/^<\\?xml\\s+.+\\?>/', $buffer)) {
         $buffer = static::declaration(Core\Data\Charset::UTF_8_ENCODING) . "\n" . $buffer;
     }
     $xml = new static($buffer);
     return $xml;
 }