public function testDump()
 {
     $testContent = "Foo Content";
     $testFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'propel_test_' . microtime();
     $parser = AbstractParser::getParser('XML');
     $parser->dump($testContent, $testFile);
     $content = file_get_contents($testFile);
     $this->assertEquals($testContent, $content);
     unlink($testFile);
 }
Example #2
0
 /**
  * Export the current object properties to a string, using a given parser format
  * <code>
  * $book = BookQuery::create()->findPk(9012);
  * echo $book->exportTo('JSON');
  *  => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
  * </code>
  *
  * @param  mixed   $parser                 A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV')
  * @param  boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE.
  * @return string  The exported data
  */
 public function exportTo($parser, $includeLazyLoadColumns = true)
 {
     if (!$parser instanceof AbstractParser) {
         $parser = AbstractParser::getParser($parser);
     }
     return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true));
 }
Example #3
0
 /**
  * Populate the current object from a string, using a given parser format
  * <code>
  * $book = new Book();
  * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
  * </code>
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
  * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
  * The default key type is the column's TableMap::TYPE_PHPNAME.
  *
  * @param mixed $parser A AbstractParser instance,
  *                       or a format name ('XML', 'YAML', 'JSON', 'CSV')
  * @param string $data The source data to import from
  * @param string $keyType The type of keys the array uses.
  *
  * @return $this|\JaCategorias The current object, for fluid interface
  */
 public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME)
 {
     if (!$parser instanceof AbstractParser) {
         $parser = AbstractParser::getParser($parser);
     }
     $this->fromArray($parser->toArray($data), $keyType);
     return $this;
 }
 /**
  * Export the current collection to a string, using a given parser format
  * <code>
  * $books = BookQuery::create()->find();
  * echo $book->exportTo('JSON');
  *  => {{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}}');
  * </code>
  *
  * A OnDemandCollection cannot be exported. Any attempt will result in a PropelException being thrown.
  *
  * @param mixed   $parser    A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV')
  * @param boolean $usePrefix (optional) If true, the returned element keys will be prefixed with the
  *                                            model class name ('Article_0', 'Article_1', etc). Defaults to TRUE.
  *                                            Not supported by ArrayCollection, as ArrayFormatter has
  *                                            already created the array used here with integers as keys.
  * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE.
  *                                            Not supported by ArrayCollection, as ArrayFormatter has
  *                                            already included lazy-load columns in the array used here.
  * @return string The exported data
  */
 public function exportTo($parser, $usePrefix = true, $includeLazyLoadColumns = true)
 {
     if (!$parser instanceof AbstractParser) {
         $parser = AbstractParser::getParser($parser);
     }
     return $parser->listFromArray($this->toArray(null, $usePrefix, TableMap::TYPE_PHPNAME, $includeLazyLoadColumns));
 }