gpt4 book ai didi

php - Doctrine 自定义 MariaDB 平台

转载 作者:行者123 更新时间:2023-12-04 14:48:13 24 4
gpt4 key购买 nike

我创建了 CustomDbPlatform 扩展 MySqlPlatform 基于现有的 MariaDb1027Platform 和自定义 getDefaultValueDeclarationSQL 方法。我无法扩展 MariaDbPlatform,因为它是最后一节课。

class CustomDbPlatform extends MySqlPlatform
{
public function getJsonTypeDeclarationSQL(array $column): string
{
return 'LONGTEXT';
}

protected function getReservedKeywordsClass(): string
{
return MariaDb102Keywords::class;
}

protected function initializeDoctrineTypeMappings(): void
{
parent::initializeDoctrineTypeMappings();

$this->doctrineTypeMapping['json'] = Types::JSON;
}

public function getDefaultValueDeclarationSQL($column): string
{
if (isset($column['default'], $column['type'])) {
$default = $column['default'];
$type = $column['type'];

if ($type instanceof DateTimePrecisionType && stripos($default, $this->getCurrentTimestampSQL()) !== false) {
if (isset($column['length']) && $column['length'] > 0 && $column['length'] < 255) {
return ' DEFAULT ' . sprintf('%s(%d)', $this->getCurrentTimestampSQL(), $column['length']);

}

return ' DEFAULT ' . $this->getCurrentTimestampSQL();
}
}

return parent::getDefaultValueDeclarationSQL($column);
}
}

不幸的是,在模式更新期间,Doctrine 强制使用新的表列定义更新基本上整个模式。此问题是由专门检查 MariaDb1027PlatformMySqlSchemaManager 引起的。

if ($this->_platform instanceof MariaDb1027Platform) {
$columnDefault = $this->getMariaDb1027ColumnDefault($this->_platform, $tableColumn['default']);
} else {
$columnDefault = $tableColumn['default'];
}

如何让 Doctrine 将我的 CustomDbPlatform 识别为 MariaDb1027Platform?制作自定义 SchemaManager 似乎有点矫枉过正。

使用

  • 交响乐 4.4
  • Doctrine 2
  • MariaDB 10.3

最佳答案

如果你想扩展MariaDb1027Platform,唯一的方法是:

  1. https://github.com/doctrine/dbal/blob/3.1.x/src/Platforms/MariaDb1027Platform.php复制平台类文件,
  2. 地点在您的项目中
  3. 删除final kw
  4. 在从 DBAL 库自动加载类之前加载此文件 - 您可以使用 composer autoload files 部分

此外,我还创建了 PR https://github.com/doctrine/dbal/pull/4909看看维护者是否想正式支持它。

关于php - Doctrine 自定义 MariaDB 平台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69570657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com