';
$buffer[] = '';
$buffer[] = ' ';
if ($this->options->withStructure)
{
$buffer = array_merge($buffer, $this->buildXmlStructure());
}
if ($this->options->withData)
{
$buffer = array_merge($buffer, $this->buildXmlData());
}
$buffer[] = ' ';
$buffer[] = '';
return implode("\n", $buffer);
}
/**
* Builds the XML structure to export.
*
* @return array An array of XML lines (strings).
*
* @since 1.0
* @throws \Exception if an error occurs.
*/
protected function buildXmlStructure()
{
$buffer = [];
foreach ($this->from as $table)
{
// Replace the magic prefix if found.
$table = $this->getGenericTableName($table);
// Get the details columns information.
$fields = $this->db->getTableColumns($table, false);
$keys = $this->db->getTableKeys($table);
$buffer[] = ' ';
foreach ($fields as $field)
{
$buffer[] = ' Default) ? ' Default="' . $field->Default . '"' : '') . ' Extra="' . $field->Extra . '"' .
' />';
}
foreach ($keys as $key)
{
$buffer[] = ' ';
}
$buffer[] = ' ';
}
return $buffer;
}
/**
* Checks if all data and options are in order prior to exporting.
*
* @return $this
*
* @since 1.0
* @throws \RuntimeException
*/
public function check()
{
// Check if the db connector has been set.
if (!($this->db instanceof MysqliDriver))
{
throw new \RuntimeException('Database connection wrong type.');
}
// Check if the tables have been specified.
if (empty($this->from))
{
throw new \RuntimeException('ERROR: No Tables Specified');
}
return $this;
}
}