/**
  * Creates a new model parse error exception instance
  *
  * @param MFile $modelFile The file that caused the parse error
  * @param MString|null $description The description of the error
  * @param MException|null $previous The previous exception that cause this error to
  * happen
  *
  * @return MModelParseErrorException The new exception instance
  */
 public function __construct(MFile $modelFile, MString $description = null, MException $previous = null)
 {
     $d = $description;
     if ($d == null) {
         $d = Sf("Model Parse Error on file [%s]", $modelFile->path()->stringValue());
     } else {
         $d = $d->stringByAppendingString(Sf("\nModel file: [%s]", $modelFile->path()->stringValue()));
     }
     parent::__construct($d, MException::MODEL_PARSE_ERROR_EXCEPTION_CODE, $previous);
     $this->modelFile = $modelFile;
 }
Ejemplo n.º 2
0
 /**
  * 
  *
  * @return MFileInputStream
  */
 public function __construct(MFile $file)
 {
     parent::__construct();
     $this->file = $file;
     $this->handle = fopen($file->path()->stringValue(), 'r');
 }
 /**
  * Parses one or more Managed Objects from inside the specified XML file
  * and inserts them into this Managed Object Context
  *
  * @param MFile $file An XML file containing the objects to be parsed
  * @param callable $callback A callback function which will be called every time a new
  * object is parsed and added into the Managed Object Context. The method signature for the
  * callback is callback(MManagedObject $object);
  *
  * @return MArray An Array containing the parsed objects
  */
 public function parseObjectsFromFile(MFile $file, callable $callback = null)
 {
     if (!$file->exists()) {
         throw new MFileNotFoundException($file->path());
     }
     $xml = simplexml_load_file($file->path()->stringValue());
     return $this->parseObjectsFromXML($xml, $callback);
 }