Unverified Commit 397fe2b9 authored by Jonathan H. Wage's avatar Jonathan H. Wage Committed by Sergei Morozov

Remove deprecated stuff for 3.0

parent ef6b84ef
......@@ -7,8 +7,6 @@ namespace Doctrine\DBAL;
use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\Logging\NullLogger;
use Doctrine\DBAL\Logging\SQLLogger;
use Doctrine\DBAL\Schema\AbstractAsset;
use function preg_match;
/**
* Configuration container for the Doctrine DBAL.
......@@ -58,36 +56,6 @@ class Configuration
$this->_attributes['resultCacheImpl'] = $cacheImpl;
}
/**
* Sets the filter schema assets expression.
*
* Only include tables/sequences matching the filter expression regexp in
* schema instances generated for the active connection when calling
* {AbstractSchemaManager#createSchema()}.
*
* @deprecated Use Configuration::setSchemaAssetsFilter() instead
*/
public function setFilterSchemaAssetsExpression(?string $filterExpression) : void
{
$this->_attributes['filterSchemaAssetsExpression'] = $filterExpression;
if ($filterExpression) {
$this->_attributes['filterSchemaAssetsExpressionCallable'] = $this->buildSchemaAssetsFilterFromExpression($filterExpression);
} else {
$this->_attributes['filterSchemaAssetsExpressionCallable'] = null;
}
}
private function buildSchemaAssetsFilterFromExpression(string $filterExpression) : callable
{
return static function ($assetName) use ($filterExpression) : bool {
if ($assetName instanceof AbstractAsset) {
$assetName = $assetName->getName();
}
return preg_match($filterExpression, $assetName) > 0;
};
}
/**
* Sets the callable to use to filter schema assets.
*/
......
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\DBALException;
use function sprintf;
final class UnknownFetchMode extends DBALException
{
/**
* @param mixed $fetchMode
*/
public static function new($fetchMode) : self
{
return new self(sprintf('Unknown fetch mode %d.', $fetchMode));
}
}
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\DBALException;
use function sprintf;
final class UnknownParamType extends DBALException
{
public static function new(int $type) : self
{
return new self(sprintf('Unknown param type %d.', $type));
}
}
......@@ -9,10 +9,7 @@ use function sprintf;
final class UnknownFetchMode extends MysqliException
{
/**
* @param mixed $fetchMode
*/
public static function new($fetchMode) : self
public static function new(int $fetchMode) : self
{
return new self(sprintf('Unknown fetch mode %d.', $fetchMode));
}
......
......@@ -4,19 +4,18 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Exception\UnknownFetchMode;
use Doctrine\DBAL\Driver\Exception\UnknownParamType;
use Doctrine\DBAL\Exception\InvalidColumnIndex;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use PDO;
use const E_USER_DEPRECATED;
use function array_slice;
use function assert;
use function count;
use function func_get_args;
use function is_array;
use function sprintf;
use function trigger_error;
/**
* The PDO implementation of the Statement interface.
......@@ -204,13 +203,7 @@ class PDOStatement implements IteratorAggregate, Statement
private function convertParamType(int $type) : int
{
if (! isset(self::PARAM_TYPE_MAP[$type])) {
// TODO: next major: throw an exception
@trigger_error(sprintf(
'Using a PDO parameter type (%d given) is deprecated and will cause an error in Doctrine DBAL 3.0.',
$type
), E_USER_DEPRECATED);
return $type;
throw UnknownParamType::new($type);
}
return self::PARAM_TYPE_MAP[$type];
......@@ -224,14 +217,7 @@ class PDOStatement implements IteratorAggregate, Statement
private function convertFetchMode(int $fetchMode) : int
{
if (! isset(self::FETCH_MODE_MAP[$fetchMode])) {
// TODO: next major: throw an exception
@trigger_error(sprintf(
'Using a PDO fetch mode or their combination (%d given)' .
' is deprecated and will cause an error in Doctrine DBAL 3.0.',
$fetchMode
), E_USER_DEPRECATED);
return $fetchMode;
throw UnknownFetchMode::new($fetchMode);
}
return self::FETCH_MODE_MAP[$fetchMode];
......
......@@ -122,10 +122,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/**
* Append to any INSERT query to retrieve the last insert id.
*
* @deprecated This constant has been deprecated and will be made private in 3.0
*/
public const LAST_INSERT_ID_SQL = ';SELECT SCOPE_IDENTITY() AS LastInsertId;';
private const LAST_INSERT_ID_SQL = ';SELECT SCOPE_IDENTITY() AS LastInsertId;';
/**
* @param resource $conn
......
......@@ -2089,7 +2089,7 @@ abstract class AbstractPlatform
$chunks[] = 'CLUSTERED';
}
$chunks[] = sprintf('(%s)', $this->getIndexFieldDeclarationListSQL($columns));
$chunks[] = sprintf('(%s)', $this->getColumnsFieldDeclarationListSQL($columns));
return implode(' ', $chunks);
}
......@@ -2134,22 +2134,23 @@ abstract class AbstractPlatform
/**
* Obtains DBMS specific SQL code portion needed to set an index
* declaration to be used in statements like CREATE TABLE.
*
* @param mixed[]|Index $columnsOrIndex array declaration is deprecated, prefer passing Index to this method
*/
public function getIndexFieldDeclarationListSQL($columnsOrIndex) : string
public function getIndexFieldDeclarationListSQL(Index $index) : string
{
if ($columnsOrIndex instanceof Index) {
return implode(', ', $columnsOrIndex->getQuotedColumns($this));
}
if (! is_array($columnsOrIndex)) {
throw new InvalidArgumentException('Fields argument should be an Index or array.');
return implode(', ', $index->getQuotedColumns($this));
}
/**
* Obtains DBMS specific SQL code portion needed to set an index
* declaration to be used in statements like CREATE TABLE.
*
* @param mixed[] $columns
*/
public function getColumnsFieldDeclarationListSQL(array $columns) : string
{
$ret = [];
foreach ($columnsOrIndex as $column => $definition) {
foreach ($columns as $column => $definition) {
if (is_array($definition)) {
$ret[] = $column;
} else {
......
......@@ -1135,8 +1135,8 @@ SQL
'int8' => 'bigint',
'integer' => 'integer',
'interval' => 'string',
'json' => Type::JSON,
'jsonb' => Type::JSON,
'json' => 'json',
'jsonb' => 'json',
'money' => 'decimal',
'numeric' => 'decimal',
'serial' => 'integer',
......
......@@ -584,9 +584,9 @@ class SQLAnywherePlatform extends AbstractPlatform
}
return $sql .
'FOREIGN KEY (' . $this->getIndexFieldDeclarationListSQL($localColumns) . ') ' .
'FOREIGN KEY (' . $this->getColumnsFieldDeclarationListSQL($localColumns) . ') ' .
'REFERENCES ' . $foreignKey->getQuotedForeignTableName($this) .
' (' . $this->getIndexFieldDeclarationListSQL($foreignColumns) . ')';
' (' . $this->getColumnsFieldDeclarationListSQL($foreignColumns) . ')';
}
/**
......@@ -1419,10 +1419,10 @@ SQL
}
if ($constraint->isPrimary()) {
return $sql . 'PRIMARY KEY ' . $flags . '(' . $this->getIndexFieldDeclarationListSQL($constraintColumns) . ')';
return $sql . 'PRIMARY KEY ' . $flags . '(' . $this->getColumnsFieldDeclarationListSQL($constraintColumns) . ')';
}
return $sql . 'UNIQUE ' . $flags . '(' . $this->getIndexFieldDeclarationListSQL($constraintColumns) . ')';
return $sql . 'UNIQUE ' . $flags . '(' . $this->getColumnsFieldDeclarationListSQL($constraintColumns) . ')';
}
/**
......
......@@ -33,15 +33,12 @@ class SQLParserUtils
/**#@+
* Quote characters within string literals can be preceded by a backslash.
*
* @deprecated Will be removed as internal implementation details.
*/
public const ESCAPED_SINGLE_QUOTED_TEXT = "(?:'(?:\\\\)+'|'(?:[^'\\\\]|\\\\'?|'')*')";
public const ESCAPED_DOUBLE_QUOTED_TEXT = '(?:"(?:\\\\)+"|"(?:[^"\\\\]|\\\\"?)*")';
public const ESCAPED_BACKTICK_QUOTED_TEXT = '(?:`(?:\\\\)+`|`(?:[^`\\\\]|\\\\`?)*`)';
/**#@-*/
private const ESCAPED_SINGLE_QUOTED_TEXT = "(?:'(?:\\\\)+'|'(?:[^'\\\\]|\\\\'?|'')*')";
private const ESCAPED_DOUBLE_QUOTED_TEXT = '(?:"(?:\\\\)+"|"(?:[^"\\\\]|\\\\"?)*")';
private const ESCAPED_BACKTICK_QUOTED_TEXT = '(?:`(?:\\\\)+`|`(?:[^`\\\\]|\\\\`?)*`)';
private const ESCAPED_BRACKET_QUOTED_TEXT = '(?<!\b(?i:ARRAY))\[(?:[^\]])*\]';
/**#@-*/
/**
* Returns a zero-indexed list of placeholder position.
......
......@@ -4,12 +4,10 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Schema\Exception\UnknownColumnOption;
use Doctrine\DBAL\Types\Type;
use const E_USER_DEPRECATED;
use function array_merge;
use function method_exists;
use function sprintf;
use function trigger_error;
/**
* Object representation of a database column.
......@@ -74,16 +72,11 @@ class Column extends AbstractAsset
{
foreach ($options as $name => $value) {
$method = 'set' . $name;
if (! method_exists($this, $method)) {
// next major: throw an exception
@trigger_error(sprintf(
'The "%s" column option is not supported,' .
' setting it is deprecated and will cause an error in Doctrine DBAL 3.0',
$name
), E_USER_DEPRECATED);
continue;
if (! method_exists($this, $method)) {
throw UnknownColumnOption::new($name);
}
$this->$method($value);
}
......
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Schema\Exception;
use Doctrine\DBAL\Schema\SchemaException;
use function sprintf;
final class UnknownColumnOption extends SchemaException
{
public static function new(string $name) : self
{
return new self(
sprintf('The "%s" column option is not supported.', $name)
);
}
}
......@@ -38,7 +38,7 @@ class BinaryType extends Type
}
if (! is_string($value)) {
throw ValueNotConvertible::new($value, self::BINARY);
throw ValueNotConvertible::new($value, Types::BINARY);
}
return $value;
......
......@@ -45,7 +45,7 @@ class BlobType extends Type
}
if (! is_resource($value)) {
throw ValueNotConvertible::new($value, self::BLOB);
throw ValueNotConvertible::new($value, Types::BLOB);
}
return $value;
......
......@@ -17,78 +17,6 @@ use function get_class;
*/
abstract class Type
{
/** @deprecated Use {@see Types::BIGINT} instead. */
public const BIGINT = Types::BIGINT;
/** @deprecated Use {@see Types::BINARY} instead. */
public const BINARY = Types::BINARY;
/** @deprecated Use {@see Types::BLOB} instead. */
public const BLOB = Types::BLOB;
/** @deprecated Use {@see Types::BOOLEAN} instead. */
public const BOOLEAN = Types::BOOLEAN;
/** @deprecated Use {@see Types::DATE_MUTABLE} instead. */
public const DATE = Types::DATE_MUTABLE;
/** @deprecated Use {@see Types::DATE_IMMUTABLE} instead. */
public const DATE_IMMUTABLE = Types::DATE_IMMUTABLE;
/** @deprecated Use {@see Types::DATEINTERVAL} instead. */
public const DATEINTERVAL = Types::DATEINTERVAL;
/** @deprecated Use {@see Types::DATETIME_MUTABLE} instead. */
public const DATETIME = Types::DATETIME_MUTABLE;
/** @deprecated Use {@see Types::DATETIME_IMMUTABLE} instead. */
public const DATETIME_IMMUTABLE = Types::DATETIME_IMMUTABLE;
/** @deprecated Use {@see Types::DATETIMETZ_MUTABLE} instead. */
public const DATETIMETZ = Types::DATETIMETZ_MUTABLE;
/** @deprecated Use {@see Types::DATETIMETZ_IMMUTABLE} instead. */
public const DATETIMETZ_IMMUTABLE = Types::DATETIMETZ_IMMUTABLE;
/** @deprecated Use {@see Types::DECIMAL} instead. */
public const DECIMAL = Types::DECIMAL;
/** @deprecated Use {@see Types::FLOAT} instead. */
public const FLOAT = Types::FLOAT;
/** @deprecated Use {@see Types::GUID} instead. */
public const GUID = Types::GUID;
/** @deprecated Use {@see Types::INTEGER} instead. */
public const INTEGER = Types::INTEGER;
/** @deprecated Use {@see Types::JSON} instead. */
public const JSON = Types::JSON;
/** @deprecated Use {@see Types::OBJECT} instead. */
public const OBJECT = Types::OBJECT;
/** @deprecated Use {@see Types::SIMPLE_ARRAY} instead. */
public const SIMPLE_ARRAY = Types::SIMPLE_ARRAY;
/** @deprecated Use {@see Types::SMALLINT} instead. */
public const SMALLINT = Types::SMALLINT;
/** @deprecated Use {@see Types::STRING} instead. */
public const STRING = Types::STRING;
/** @deprecated Use {@see Types::ARRAY} instead. */
public const TARRAY = Types::ARRAY;
/** @deprecated Use {@see Types::TEXT} instead. */
public const TEXT = Types::TEXT;
/** @deprecated Use {@see Types::TIME_MUTABLE} instead. */
public const TIME = Types::TIME_MUTABLE;
/** @deprecated Use {@see Types::TIME_IMMUTABLE} instead. */
public const TIME_IMMUTABLE = Types::TIME_IMMUTABLE;
/**
* The map of supported doctrine mapping types.
*/
......
......@@ -34,9 +34,6 @@ final class Types
public const TIME_MUTABLE = 'time';
public const TIME_IMMUTABLE = 'time_immutable';
/** @deprecated json_array type is deprecated, use {@see self::JSON} instead. */
public const JSON_ARRAY = 'json_array';
private function __construct()
{
}
......
......@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Doctrine\Tests\DBAL\Functional;
use Doctrine\DBAL\Driver\Exception\UnknownFetchMode;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Schema\Table;
use Doctrine\Tests\DbalFunctionalTestCase;
......@@ -39,6 +40,9 @@ class PDOStatementTest extends DbalFunctionalTestCase
'name' => 'Bob',
]);
self::expectException(UnknownFetchMode::class);
self::expectExceptionMessage('Unknown fetch mode 12.');
$data = $this->connection->query('SELECT id, name FROM stmt_test ORDER BY id')
->fetchAll(PDO::FETCH_KEY_PAIR);
......
......@@ -7,7 +7,7 @@ namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use function assert;
class PostgreSqlPlatformTest extends AbstractPostgreSqlPlatformTestCase
......@@ -87,9 +87,9 @@ class PostgreSqlPlatformTest extends AbstractPostgreSqlPlatformTestCase
public function testInitializesJsonTypeMapping() : void
{
self::assertTrue($this->platform->hasDoctrineTypeMappingFor('json'));
self::assertEquals(Type::JSON, $this->platform->getDoctrineTypeMapping('json'));
self::assertEquals(Types::JSON, $this->platform->getDoctrineTypeMapping('json'));
self::assertTrue($this->platform->hasDoctrineTypeMappingFor('jsonb'));
self::assertEquals(Type::JSON, $this->platform->getDoctrineTypeMapping('jsonb'));
self::assertEquals(Types::JSON, $this->platform->getDoctrineTypeMapping('jsonb'));
}
/**
......
......@@ -8,6 +8,7 @@ use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Exception\UnknownColumnOption;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use PHPUnit\Framework\TestCase;
......@@ -64,13 +65,17 @@ class ColumnTest extends TestCase
public function testSettingUnknownOptionIsStillSupported() : void
{
$this->expectNotToPerformAssertions();
self::expectException(UnknownColumnOption::class);
self::expectExceptionMessage('The "unknown_option" column option is not supported.');
new Column('foo', $this->createMock(Type::class), ['unknown_option' => 'bar']);
}
public function testOptionsShouldNotBeIgnored() : void
{
self::expectException(UnknownColumnOption::class);
self::expectExceptionMessage('The "unknown_option" column option is not supported.');
$col1 = new Column('bar', Type::getType(Types::INTEGER), ['unknown_option' => 'bar', 'notnull' => true]);
self::assertTrue($col1->getNotnull());
......
......@@ -14,6 +14,7 @@ use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\UniqueConstraint;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Doctrine\Tests\DbalTestCase;
use function array_keys;
use function current;
......@@ -905,10 +906,10 @@ class TableTest extends DbalTestCase
public function testUniqueConstraintWithEmptyName() : void
{
$columns = [
new Column('column1', Type::getType(Type::STRING)),
new Column('column2', Type::getType(Type::STRING)),
new Column('column3', Type::getType(Type::STRING)),
new Column('column4', Type::getType(Type::STRING)),
new Column('column1', Type::getType(Types::STRING)),
new Column('column2', Type::getType(Types::STRING)),
new Column('column3', Type::getType(Types::STRING)),
new Column('column4', Type::getType(Types::STRING)),
];
$uniqueConstraints = [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment