예제 #1
0
 /**
  * Saves the schema definition in $schema to the file $file.
  * @todo throw exception when file can not be opened
  *
  * @param string      $file
  * @param ezcDbSchema $dbSchema
  */
 public function saveToFile($file, ezcDbSchema $dbSchema)
 {
     $schema = $dbSchema->getSchema();
     $data = $dbSchema->getData();
     $fileData = '<?php return ' . var_export(array($schema, $data), true) . '; ?>';
     if (!@file_put_contents($file, (string) $fileData)) {
         throw new ezcBaseFilePermissionException($file, ezcBaseFileException::WRITE);
     }
 }
예제 #2
0
 /**
  * Writes the schema definition in $dbSchema to the file $file.
  *
  * @param string      $file
  * @param ezcDbSchema $dbSchema
  * @todo throw exception when file can not be opened
  */
 public function saveToFile($file, ezcDbSchema $dbSchema)
 {
     $schema = $dbSchema->getSchema();
     $data = $dbSchema->getData();
     $this->writer = new XMLWriter();
     if (!@$this->writer->openUri($file)) {
         throw new ezcBaseFilePermissionException($file, ezcBaseFileException::WRITE);
     }
     $this->writer->startDocument('1.0', 'utf-8');
     $this->writer->setIndent(true);
     $this->writer->startElement('database');
     foreach ($schema as $tableName => $table) {
         $this->writer->flush();
         $this->writeTable($tableName, $table);
     }
     $this->writer->endElement();
     $this->writer->endDocument();
 }