mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-24 07:08:40 +00:00
add db formats
This commit is contained in:
parent
5892819542
commit
3e0d7ec68b
|
|
@ -48,6 +48,11 @@ final class MysqlConnection extends ConnectionAbstract
|
|||
$this->grammar = new MysqlGrammar();
|
||||
$this->schemaGrammar = new MysqlSchemaGrammar();
|
||||
|
||||
if (isset($dbdata['datetimeformat'])) {
|
||||
$this->grammar->setDateTimeFormat($dbdata['datetimeformat']);
|
||||
$this->schemaGrammar->setDateTimeFormat($dbdata['datetimeformat']);
|
||||
}
|
||||
|
||||
$this->dbdata = $dbdata;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,11 @@ final class PostgresConnection extends ConnectionAbstract
|
|||
$this->grammar = new PostgresGrammar();
|
||||
$this->schemaGrammar = new PostgresSchemaGrammar();
|
||||
|
||||
if (isset($dbdata['datetimeformat'])) {
|
||||
$this->grammar->setDateTimeFormat($dbdata['datetimeformat']);
|
||||
$this->schemaGrammar->setDateTimeFormat($dbdata['datetimeformat']);
|
||||
}
|
||||
|
||||
$this->dbdata = $dbdata;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,11 @@ final class SQLiteConnection extends ConnectionAbstract
|
|||
$this->grammar = new SQLiteGrammar();
|
||||
$this->schemaGrammar = new SQLiteSchemaGrammar();
|
||||
|
||||
if (isset($dbdata['datetimeformat'])) {
|
||||
$this->grammar->setDateTimeFormat($dbdata['datetimeformat']);
|
||||
$this->schemaGrammar->setDateTimeFormat($dbdata['datetimeformat']);
|
||||
}
|
||||
|
||||
$this->dbdata = $dbdata;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,11 @@ final class SqlServerConnection extends ConnectionAbstract
|
|||
$this->grammar = new SqlServerGrammar();
|
||||
$this->schemaGrammar = new SqlServerSchemaGrammar();
|
||||
|
||||
if (isset($dbdata['datetimeformat'])) {
|
||||
$this->grammar->setDateTimeFormat($dbdata['datetimeformat']);
|
||||
$this->schemaGrammar->setDateTimeFormat($dbdata['datetimeformat']);
|
||||
}
|
||||
|
||||
$this->dbdata = $dbdata;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -230,6 +230,17 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
*/
|
||||
protected static int $relations = RelationType::ALL;
|
||||
|
||||
/**
|
||||
* Datetime format of the database datetime
|
||||
*
|
||||
* This is only for the datetime stored in the database not the generated query.
|
||||
* For the query check the datetime in Grammar:$datetimeFormat
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $datetimeFormat = 'Y-m-d H:i:s';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
|
@ -1064,7 +1075,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
} elseif ($type === 'bool') {
|
||||
return (bool) $value;
|
||||
} elseif ($type === 'DateTime' || $type === 'DateTimeImmutable') {
|
||||
return $value === null ? null : $value->format('Y-m-d H:i:s');
|
||||
return $value === null ? null : $value->format(self::$datetimeFormat);
|
||||
} elseif ($type === 'Json' || $value instanceof \JsonSerializable) {
|
||||
return (string) \json_encode($value);
|
||||
} elseif ($type === 'Serializable') {
|
||||
|
|
|
|||
|
|
@ -86,6 +86,28 @@ abstract class GrammarAbstract
|
|||
'MIN(',
|
||||
];
|
||||
|
||||
/**
|
||||
* Datetime format.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected string $datetimeFormat = 'Y-m-d H:i:s';
|
||||
|
||||
/**
|
||||
* Set the datetime format
|
||||
*
|
||||
* @param string $format Datetime format
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setDateTimeFormat(string $format) : void
|
||||
{
|
||||
$this->datetimeFormat = $format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile to query.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -340,7 +340,7 @@ class Grammar extends GrammarAbstract
|
|||
|
||||
return '(' . \rtrim($values, ', ') . ')';
|
||||
} elseif ($value instanceof \DateTime) {
|
||||
return $query->quote($value->format('Y-m-d H:i:s'));
|
||||
return $query->quote($value->format($this->datetimeFormat));
|
||||
} elseif ($value === null) {
|
||||
return 'NULL';
|
||||
} elseif (\is_bool($value)) {
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ class Tar implements ArchiveInterface
|
|||
$source = $relative;
|
||||
}
|
||||
|
||||
$source = \str_replace('\\', '/', $source);
|
||||
$relative = \str_replace('\\', '/', $relative);
|
||||
|
||||
if (\is_dir($source)) {
|
||||
$files = new \RecursiveIteratorIterator(
|
||||
new \RecursiveDirectoryIterator($source),
|
||||
|
|
@ -67,7 +70,7 @@ class Tar implements ArchiveInterface
|
|||
|
||||
$absolute = \realpath($file);
|
||||
$absolute = \str_replace('\\', '/', (string) $absolute);
|
||||
$dir = \str_replace($source . '/', '', $relative . '/' . $absolute);
|
||||
$dir = \str_replace($source . '/', '', \rtrim($relative, '/\\') . '/' . \ltrim($absolute, '/\\'));
|
||||
|
||||
if (\is_dir($absolute)) {
|
||||
$tar->addEmptyDir($dir . '/');
|
||||
|
|
|
|||
|
|
@ -54,6 +54,9 @@ class Zip implements ArchiveInterface
|
|||
$source = $relative;
|
||||
}
|
||||
|
||||
$source = \str_replace('\\', '/', $source);
|
||||
$relative = \str_replace('\\', '/', $relative);
|
||||
|
||||
if (\is_dir($source)) {
|
||||
$files = new \RecursiveIteratorIterator(
|
||||
new \RecursiveDirectoryIterator($source),
|
||||
|
|
@ -72,7 +75,7 @@ class Zip implements ArchiveInterface
|
|||
|
||||
$absolute = \realpath($file);
|
||||
$absolute = \str_replace('\\', '/', (string) $absolute);
|
||||
$dir = \str_replace($source . '/', '', $relative . '/' . $absolute);
|
||||
$dir = \str_replace($source . '/', '', \rtrim($relative, '/\\') . '/' . \ltrim($absolute, '/\\'));
|
||||
|
||||
if (\is_dir($absolute)) {
|
||||
$zip->addEmptyDir($dir . '/');
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user