Skip to content

Commit

Permalink
Extract constants for built-in types from Type to DefaultTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
Majkl578 committed Nov 25, 2018
1 parent 296b0e5 commit dc28b62
Show file tree
Hide file tree
Showing 52 changed files with 260 additions and 126 deletions.
13 changes: 13 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Upgrade to 2.10

## Deprecated `Type::*` constants

The constants for built-in types have been moved from `Doctrine\DBAL\Types\Type` to a separate class `Doctrine\DBAL\Types\DefaultTypes`.

Some of the constants were renamed:
* `TARRAY`-> `ARRAY`
* `DATE` -> `DATE_MUTABLE`
* `DATETIME` -> `DATETIME_MUTABLE`
* `DATETIMETZ` -> `DATETIMETZ_MUTABLE`
* `TIME` -> `TIME_MUTABLE`

# Upgrade to 2.9

## Deprecated `Configuration::getFilterSchemaAssetsExpression()`, `::setFilterSchemaAssetsExpression()` and `AbstractSchemaManager::getFilterSchemaAssetsExpression()`.
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/DBAL/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Types\DefaultTypes;
use Doctrine\DBAL\Types\Type;
use function array_merge;
use function count;
Expand Down Expand Up @@ -97,7 +98,7 @@ public function initializeDoctrineTypeMappings()
*/
public function isCommentedDoctrineType(Type $doctrineType)
{
if ($doctrineType->getName() === Type::BOOLEAN) {
if ($doctrineType->getName() === DefaultTypes::BOOLEAN) {
// We require a commented boolean type in order to distinguish between boolean and smallint
// as both (have to) map to the same native type.
return true;
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Doctrine\DBAL\Platforms;

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\DefaultTypes;

/**
* Provides the behavior, features and SQL dialect of the MariaDB 10.2 (10.2.7 GA) database platform.
Expand Down Expand Up @@ -36,6 +36,6 @@ protected function initializeDoctrineTypeMappings() : void
{
parent::initializeDoctrineTypeMappings();

$this->doctrineTypeMapping['json'] = Type::JSON;
$this->doctrineTypeMapping['json'] = DefaultTypes::JSON;
}
}
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Platforms/MySQL57Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\DefaultTypes;

/**
* Provides the behavior, features and SQL dialect of the MySQL 5.7 (5.7.9 GA) database platform.
Expand Down Expand Up @@ -66,6 +66,6 @@ protected function initializeDoctrineTypeMappings()
{
parent::initializeDoctrineTypeMappings();

$this->doctrineTypeMapping['json'] = Type::JSON;
$this->doctrineTypeMapping['json'] = DefaultTypes::JSON;
}
}
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Doctrine\DBAL\Platforms;

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\DefaultTypes;
use function sprintf;

/**
Expand Down Expand Up @@ -53,7 +53,7 @@ protected function initializeDoctrineTypeMappings()
{
parent::initializeDoctrineTypeMappings();

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

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Doctrine\DBAL\Platforms;

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\DefaultTypes;

/**
* Provides the behavior, features and SQL dialect of the PostgreSQL 9.4 database platform.
Expand Down Expand Up @@ -36,6 +36,6 @@ protected function initializeDoctrineTypeMappings()
{
parent::initializeDoctrineTypeMappings();

$this->doctrineTypeMapping['jsonb'] = Type::JSON;
$this->doctrineTypeMapping['jsonb'] = DefaultTypes::JSON;
}
}
3 changes: 2 additions & 1 deletion lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Types\DefaultTypes;
use Doctrine\DBAL\Types\Type;
use const CASE_LOWER;
use function array_change_key_case;
Expand Down Expand Up @@ -456,7 +457,7 @@ protected function _getPortableTableColumnDefinition($tableColumn)
$column->setPlatformOption('collation', $tableColumn['collation']);
}

if (in_array($column->getType()->getName(), [Type::JSON_ARRAY, Type::JSON], true)) {
if (in_array($column->getType()->getName(), [DefaultTypes::JSON_ARRAY, DefaultTypes::JSON], true)) {
$column->setPlatformOption('jsonb', $jsonb);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\DBAL\Schema\Synchronizer\AbstractSchemaSynchronizer;
use Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer;
use Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer;
use Doctrine\DBAL\Types\DefaultTypes;
use Doctrine\DBAL\Types\Type;
use RuntimeException;
use function array_merge;
Expand Down Expand Up @@ -240,12 +241,12 @@ private function getFederationTypeDefaultValue()
$federationType = Type::getType($this->shardManager->getDistributionType());

switch ($federationType->getName()) {
case Type::GUID:
case DefaultTypes::GUID:
$defaultValue = '00000000-0000-0000-0000-000000000000';
break;
case Type::INTEGER:
case Type::SMALLINT:
case Type::BIGINT:
case DefaultTypes::INTEGER:
case DefaultTypes::SMALLINT:
case DefaultTypes::BIGINT:
$defaultValue = '0';
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/ArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
*/
public function getName()
{
return Type::TARRAY;
return DefaultTypes::ARRAY;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/BigIntType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BigIntType extends Type implements PhpIntegerMappingType
*/
public function getName()
{
return Type::BIGINT;
return DefaultTypes::BIGINT;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Types/BinaryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
}

if (! is_resource($value)) {
throw ConversionException::conversionFailed($value, self::BINARY);
throw ConversionException::conversionFailed($value, DefaultTypes::BINARY);
}

return $value;
Expand All @@ -51,7 +51,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
*/
public function getName()
{
return Type::BINARY;
return DefaultTypes::BINARY;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Types/BlobType.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
}

if (! is_resource($value)) {
throw ConversionException::conversionFailed($value, self::BLOB);
throw ConversionException::conversionFailed($value, DefaultTypes::BLOB);
}

return $value;
Expand All @@ -51,7 +51,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
*/
public function getName()
{
return Type::BLOB;
return DefaultTypes::BLOB;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/BooleanType.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
*/
public function getName()
{
return Type::BOOLEAN;
return DefaultTypes::BOOLEAN;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/DateImmutableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DateImmutableType extends DateType
*/
public function getName()
{
return Type::DATE_IMMUTABLE;
return DefaultTypes::DATE_IMMUTABLE;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/DateIntervalType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DateIntervalType extends Type
*/
public function getName()
{
return Type::DATEINTERVAL;
return DefaultTypes::DATEINTERVAL;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/DateTimeImmutableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DateTimeImmutableType extends DateTimeType
*/
public function getName()
{
return Type::DATETIME_IMMUTABLE;
return DefaultTypes::DATETIME_IMMUTABLE;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/DateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DateTimeType extends Type implements PhpDateTimeMappingType
*/
public function getName()
{
return Type::DATETIME;
return DefaultTypes::DATETIME_MUTABLE;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DateTimeTzImmutableType extends DateTimeTzType
*/
public function getName()
{
return Type::DATETIMETZ_IMMUTABLE;
return DefaultTypes::DATETIMETZ_IMMUTABLE;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/DateTimeTzType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DateTimeTzType extends Type implements PhpDateTimeMappingType
*/
public function getName()
{
return Type::DATETIMETZ;
return DefaultTypes::DATETIMETZ_MUTABLE;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DateType extends Type
*/
public function getName()
{
return Type::DATE;
return DefaultTypes::DATE_MUTABLE;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/DecimalType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DecimalType extends Type
*/
public function getName()
{
return Type::DECIMAL;
return DefaultTypes::DECIMAL;
}

/**
Expand Down
43 changes: 43 additions & 0 deletions lib/Doctrine/DBAL/Types/DefaultTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Types;

/**
* Default built-in types provided by Doctrine.
*/
final class DefaultTypes
{
public const ARRAY = 'array';
public const BIGINT = 'bigint';
public const BINARY = 'binary';
public const BLOB = 'blob';
public const BOOLEAN = 'boolean';
public const DATE_MUTABLE = 'date';
public const DATE_IMMUTABLE = 'date_immutable';
public const DATEINTERVAL = 'dateinterval';
public const DATETIME_MUTABLE = 'datetime';
public const DATETIME_IMMUTABLE = 'datetime_immutable';
public const DATETIMETZ_MUTABLE = 'datetimetz';
public const DATETIMETZ_IMMUTABLE = 'datetimetz_immutable';
public const DECIMAL = 'decimal';
public const FLOAT = 'float';
public const GUID = 'guid';
public const INTEGER = 'integer';
public const JSON = 'json';
public const OBJECT = 'object';
public const SIMPLE_ARRAY = 'simple_array';
public const SMALLINT = 'smallint';
public const STRING = 'string';
public const TEXT = 'text';
public const TIME_MUTABLE = 'time';
public const TIME_IMMUTABLE = 'time_immutable';

/** @deprecated json_array type is deprecated, use {@see DefaultTypes::JSON} instead. */
public const JSON_ARRAY = 'json_array';

private function __construct()
{
}
}
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/FloatType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class FloatType extends Type
*/
public function getName()
{
return Type::FLOAT;
return DefaultTypes::FLOAT;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/GuidType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla
*/
public function getName()
{
return Type::GUID;
return DefaultTypes::GUID;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/IntegerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class IntegerType extends Type implements PhpIntegerMappingType
*/
public function getName()
{
return Type::INTEGER;
return DefaultTypes::INTEGER;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/JsonArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
*/
public function getName()
{
return Type::JSON_ARRAY;
return DefaultTypes::JSON_ARRAY;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/JsonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
*/
public function getName()
{
return Type::JSON;
return DefaultTypes::JSON;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
*/
public function getName()
{
return Type::OBJECT;
return DefaultTypes::OBJECT;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/SimpleArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
*/
public function getName()
{
return Type::SIMPLE_ARRAY;
return DefaultTypes::SIMPLE_ARRAY;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Types/SmallIntType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SmallIntType extends Type implements PhpIntegerMappingType
*/
public function getName()
{
return Type::SMALLINT;
return DefaultTypes::SMALLINT;
}

/**
Expand Down
Loading

0 comments on commit dc28b62

Please sign in to comment.