Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate TypeRegistry as a runtime instance #5034

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,8 @@ public function isRollbackOnly()
*/
public function convertToDatabaseValue($value, $type)
{
// Either we deprecate this method, or we add the type registry as a
// dependency
return Type::getType($type)->convertToDatabaseValue($value, $this->getDatabasePlatform());
}

Expand All @@ -1612,6 +1614,7 @@ public function convertToDatabaseValue($value, $type)
*/
public function convertToPHPValue($value, $type)
{
// same as above
return Type::getType($type)->convertToPHPValue($value, $this->getDatabasePlatform());
}

Expand Down Expand Up @@ -1669,6 +1672,7 @@ private function _bindTypedValues(DriverStatement $stmt, array $params, array $t
private function getBindingInfo($value, $type): array
{
if (is_string($type)) {
// same as above
$type = Type::getType($type);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ private function initializeAllDoctrineTypeMappings(): void
{
$this->initializeDoctrineTypeMappings();

// this method has been deprecated and will be removed, no longer a blocker
foreach (Type::getTypesMap() as $typeName => $className) {
foreach (Type::getType($typeName)->getMappedDatabaseTypes($this) as $dbType) {
$this->doctrineTypeMapping[$dbType] = $typeName;
Expand Down Expand Up @@ -364,6 +365,7 @@ public function registerDoctrineTypeMapping($dbType, $doctrineType)
$dbType = strtolower($dbType);
$this->doctrineTypeMapping[$dbType] = $doctrineType;

// deprecated method, so not a big deal either
$doctrineType = Type::getType($doctrineType);

if (! $doctrineType->requiresSQLCommentHint($this)) {
Expand Down Expand Up @@ -427,6 +429,7 @@ protected function initializeCommentedDoctrineTypes()
$this->doctrineTypeComments = [];

foreach (Type::getTypesMap() as $typeName => $className) {
// again, deprecated method
$type = Type::getType($typeName);

if (! $type->requiresSQLCommentHint($this)) {
Expand Down
2 changes: 2 additions & 0 deletions src/Schema/DB2SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ protected function _getPortableTableColumnDefinition($tableColumn)
$options['precision'] = $precision;
}

// most schema managers perform that kind of call. They know about both
// the connection and the platform
return new Column($tableColumn['colname'], Type::getType($type), $options);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Schema/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ private function _createIndex(
*/
public function addColumn($name, $typeName, array $options = [])
{
// either the signature of addColumn should require a Type instance, or
// we should pass a string to Column::__construct and resolve the type later on
$column = new Column($name, Type::getType($typeName), $options);

$this->_addColumn($column);
Expand Down
1 change: 1 addition & 0 deletions src/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function bindValue($param, $value, $type = ParameterType::STRING)

if ($type !== null) {
if (is_string($type)) {
// The type registry could be obtained from the connection
$type = Type::getType($type);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Types/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static function getType($name)
*
* @throws Exception
*/
public static function addType($name, $className)
public static function addType($name, $className) // this method is only ever used in tests
{
self::getTypeRegistry()->register($name, new $className());
}
Expand All @@ -165,7 +165,7 @@ public static function addType($name, $className)
*
* @return bool TRUE if type is supported; FALSE otherwise.
*/
public static function hasType($name)
public static function hasType($name) // used once in AbstractPlatform
{
return self::getTypeRegistry()->has($name);
}
Expand All @@ -180,7 +180,7 @@ public static function hasType($name)
*
* @throws Exception
*/
public static function overrideType($name, $className)
public static function overrideType($name, $className) // used exclusively in tests
{
self::getTypeRegistry()->override($name, new $className());
}
Expand All @@ -204,7 +204,7 @@ public function getBindingType()
*
* @return string[]
*/
public static function getTypesMap()
public static function getTypesMap() // used in AbstractPlatform
{
return array_map(
static function (Type $type): string {
Expand Down