Update parser classes

This commit is contained in:
Kijin Sung 2020-06-22 11:19:26 +09:00
parent 59f14d8a3f
commit 43c5da7818
3 changed files with 26 additions and 4 deletions

View file

@ -15,10 +15,10 @@ class DBQueryParser
* @param string $filename
* @return object|false
*/
public static function loadXML($filename)
public static function loadXML(string $filename)
{
// Load the XML file.
$xml = simplexml_load_file($filename);
$xml = simplexml_load_string(file_get_contents($filename));
if ($xml === false)
{
return false;

View file

@ -9,6 +9,7 @@ class Column
{
public $name;
public $type;
public $xetype;
public $size;
public $utf8mb4 = true;
public $default_value;

View file

@ -9,20 +9,30 @@ use Rhymix\Framework\Storage;
*/
class DBTableParser
{
/**
* Mapping for XE-compatible types.
*/
protected static $_xe_types = array(
'bignumber' => 'bigint',
'number' => 'bigint',
'bigtext' => 'longtext',
'date' => 'char(14)',
);
/**
* Load a table definition XML file.
*
* @param string $filename
* @return object|false
*/
public static function loadXML($filename)
public static function loadXML(string $filename)
{
// Initialize table definition.
$table = new DBTable\Table;
$table->name = preg_replace('/\.xml$/', '', basename($filename));
// Load the XML file.
$xml = simplexml_load_file($filename);
$xml = simplexml_load_string(file_get_contents($filename));
if ($xml === false)
{
return false;
@ -36,6 +46,17 @@ class DBTableParser
$column->name = strval($column_info['name']);
$column->type = strval($column_info['type']);
// Map XE-compatible types to database native types.
if (isset(self::$_xe_types[$column->type]))
{
$column->xetype = $column->type;
$column->type = self::$_xe_types[$column->type];
}
else
{
$column->xetype = $column->type;
}
// Get the size.
if (preg_match('/^([a-z0-9_]+)\(([0-9,\s]+)\)$/i', $column->type, $matches))
{