'; $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); $sequences = $this->db->getTableSequences($table); $buffer[] = ' '; foreach ($sequences as $sequence) { $buffer[] = ' '; } foreach ($fields as $field) { $buffer[] = ' '; } foreach ($keys as $key) { $buffer[] = ' Query . '\' />'; } $buffer[] = ' '; } return $buffer; } /** * Builds the XML data to export. * * @return array An array of XML lines (strings). * * @since 2.0.0 * @throws \Exception if an error occurs. */ protected function buildXmlData() { $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); $colblob = []; foreach ($fields as $field) { // Catch blob for xml conversion // PostgreSQL binary large object type if ($field->Type == 'bytea') { $colblob[] = $field->Field; } } $query = $this->db->getQuery(true); $query->select($query->quoteName(array_keys($fields))) ->from($query->quoteName($table)); $this->db->setQuery($query); $rows = $this->db->loadObjectList(); if (!count($rows)) { continue; } $buffer[] = ' '; foreach ($rows as $row) { $buffer[] = ' '; foreach ($row as $key => $value) { if (!in_array($key, $colblob)) { $buffer[] = ' ' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . ''; } else { $buffer[] = ' ' . stream_get_contents($value) . ''; } } $buffer[] = ' '; } $buffer[] = ' '; } return $buffer; } /** * Checks if all data and options are in order prior to exporting. * * @return $this * * @since 1.5.0 * @throws \RuntimeException */ public function check() { // Check if the db connector has been set. if (!($this->db instanceof PgsqlDriver)) { 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; } }