Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
ba421d1d
Commit
ba421d1d
authored
Sep 11, 2017
by
Marco Pivetta
Committed by
GitHub
Sep 11, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2835 from greg0ire/avoid_type_to_string
Stop relying on Type::__toString
parents
6e3afd5f
9e75bb0c
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
108 additions
and
40 deletions
+108
-40
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+25
-23
SQLServerPlatform.php
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
+7
-3
SqlitePlatform.php
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
+9
-8
BigIntType.php
lib/Doctrine/DBAL/Types/BigIntType.php
+1
-1
DateTimeType.php
lib/Doctrine/DBAL/Types/DateTimeType.php
+1
-1
DateTimeTzType.php
lib/Doctrine/DBAL/Types/DateTimeTzType.php
+1
-1
IntegerType.php
lib/Doctrine/DBAL/Types/IntegerType.php
+1
-1
PhpDateTimeMappingType.php
lib/Doctrine/DBAL/Types/PhpDateTimeMappingType.php
+30
-0
PhpIntegerMappingType.php
lib/Doctrine/DBAL/Types/PhpIntegerMappingType.php
+30
-0
SmallIntType.php
lib/Doctrine/DBAL/Types/SmallIntType.php
+1
-1
DBAL461Test.php
tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL461Test.php
+2
-1
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
ba421d1d
...
...
@@ -19,29 +19,29 @@
namespace
Doctrine\DBAL\Platforms
;
use
Doctrine\
DBAL\DBALException
;
use
Doctrine\
Common\EventManager
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Schema\Identifier
;
use
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs
;
use
Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs
;
use
Doctrine\DBAL\Event\SchemaAlterTableEventArgs
;
use
Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs
;
use
Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs
;
use
Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs
;
use
Doctrine\DBAL\Event\SchemaCreateTableEventArgs
;
use
Doctrine\DBAL\Event\SchemaDropTableEventArgs
;
use
Doctrine\DBAL\Events
;
use
Doctrine\DBAL\Schema\Column
;
use
Doctrine\DBAL\Schema\ColumnDiff
;
use
Doctrine\DBAL\Schema\Constraint
;
use
Doctrine\DBAL\Schema\ForeignKeyConstraint
;
use
Doctrine\DBAL\Schema\Identifier
;
use
Doctrine\DBAL\Schema\Index
;
use
Doctrine\DBAL\Schema\Sequence
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\Index
;
use
Doctrine\DBAL\Schema\ForeignKeyConstraint
;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Schema\Column
;
use
Doctrine\DBAL\Schema\ColumnDiff
;
use
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Events
;
use
Doctrine\Common\EventManager
;
use
Doctrine\DBAL\Event\SchemaCreateTableEventArgs
;
use
Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs
;
use
Doctrine\DBAL\Event\SchemaDropTableEventArgs
;
use
Doctrine\DBAL\Event\SchemaAlterTableEventArgs
;
use
Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs
;
use
Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs
;
use
Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs
;
use
Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs
;
/**
* Base class for all DatabasePlatforms. The DatabasePlatforms are the central
...
...
@@ -1556,7 +1556,7 @@ abstract class AbstractPlatform
$columnData
[
'version'
]
=
$column
->
hasPlatformOption
(
"version"
)
?
$column
->
getPlatformOption
(
'version'
)
:
false
;
$columnData
[
'comment'
]
=
$this
->
getColumnComment
(
$column
);
if
(
strtolower
(
$columnData
[
'type'
])
==
"string"
&&
$columnData
[
'length'
]
===
null
)
{
if
(
$columnData
[
'type'
]
instanceof
Types\StringType
&&
$columnData
[
'length'
]
===
null
)
{
$columnData
[
'length'
]
=
255
;
}
...
...
@@ -2279,15 +2279,17 @@ abstract class AbstractPlatform
if
(
isset
(
$field
[
'default'
]))
{
$default
=
" DEFAULT '"
.
$field
[
'default'
]
.
"'"
;
if
(
isset
(
$field
[
'type'
]))
{
if
(
in_array
((
string
)
$field
[
'type'
],
[
"Integer"
,
"BigInt"
,
"SmallInt"
]))
{
$type
=
$field
[
'type'
];
if
(
$type
instanceof
Types\PhpIntegerMappingType
)
{
$default
=
" DEFAULT "
.
$field
[
'default'
];
}
elseif
(
in_array
((
string
)
$field
[
'type'
],
[
'DateTime'
,
'DateTimeTz'
])
&&
$field
[
'default'
]
==
$this
->
getCurrentTimestampSQL
())
{
}
elseif
(
$type
instanceof
Types\PhpDateTimeMappingType
&&
$field
[
'default'
]
==
$this
->
getCurrentTimestampSQL
())
{
$default
=
" DEFAULT "
.
$this
->
getCurrentTimestampSQL
();
}
elseif
(
(
string
)
$field
[
'type'
]
==
'Time'
&&
$field
[
'default'
]
==
$this
->
getCurrentTimeSQL
())
{
}
elseif
(
$type
instanceof
Types\TimeType
&&
$field
[
'default'
]
==
$this
->
getCurrentTimeSQL
())
{
$default
=
" DEFAULT "
.
$this
->
getCurrentTimeSQL
();
}
elseif
(
(
string
)
$field
[
'type'
]
==
'Date'
&&
$field
[
'default'
]
==
$this
->
getCurrentDateSQL
())
{
}
elseif
(
$type
instanceof
Types\DateType
&&
$field
[
'default'
]
==
$this
->
getCurrentDateSQL
())
{
$default
=
" DEFAULT "
.
$this
->
getCurrentDateSQL
();
}
elseif
(
(
string
)
$field
[
'type'
]
==
'Boolean'
)
{
}
elseif
(
$type
instanceof
Types\BooleanType
)
{
$default
=
" DEFAULT '"
.
$this
->
convertBooleans
(
$field
[
'default'
])
.
"'"
;
}
}
...
...
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
View file @
ba421d1d
...
...
@@ -27,6 +27,7 @@ use Doctrine\DBAL\Schema\Identifier;
use
Doctrine\DBAL\Schema\Index
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Types
;
/**
* The SQLServerPlatform provides the behavior, features and SQL dialect of the
...
...
@@ -1554,15 +1555,18 @@ class SQLServerPlatform extends AbstractPlatform
return
" DEFAULT '"
.
$field
[
'default'
]
.
"'"
;
}
if
(
in_array
((
string
)
$field
[
'type'
],
[
'Integer'
,
'BigInt'
,
'SmallInt'
]))
{
$type
=
$field
[
'type'
];
if
(
$type
instanceof
Types\PhpIntegerMappingType
)
{
return
" DEFAULT "
.
$field
[
'default'
];
}
if
(
in_array
((
string
)
$field
[
'type'
],
[
'DateTime'
,
'DateTimeTz'
])
&&
$field
[
'default'
]
==
$this
->
getCurrentTimestampSQL
())
{
if
(
$type
instanceof
Types\PhpDateTimeMappingType
&&
$field
[
'default'
]
==
$this
->
getCurrentTimestampSQL
())
{
return
" DEFAULT "
.
$this
->
getCurrentTimestampSQL
();
}
if
(
(
string
)
$field
[
'type'
]
==
'Boolean'
)
{
if
(
$type
instanceof
Types\BooleanType
)
{
return
" DEFAULT '"
.
$this
->
convertBooleans
(
$field
[
'default'
])
.
"'"
;
}
...
...
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
View file @
ba421d1d
...
...
@@ -27,6 +27,7 @@ use Doctrine\DBAL\Schema\Identifier;
use
Doctrine\DBAL\Schema\Index
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Types
;
/**
* The SqlitePlatform class describes the specifics and dialects of the SQLite
...
...
@@ -904,7 +905,7 @@ class SqlitePlatform extends AbstractPlatform
if
(
!
$columnDiff
->
fromColumn
instanceof
Column
||
!
$columnDiff
->
column
instanceof
Column
||
!
$columnDiff
->
column
->
getAutoincrement
()
||
!
(
string
)
$columnDiff
->
column
->
getType
()
===
'Integer'
!
$columnDiff
->
column
->
getType
()
instanceof
Types\IntegerType
)
{
continue
;
}
...
...
@@ -915,9 +916,9 @@ class SqlitePlatform extends AbstractPlatform
continue
;
}
$fromColumnType
=
(
string
)
$columnDiff
->
fromColumn
->
getType
();
$fromColumnType
=
$columnDiff
->
fromColumn
->
getType
();
if
(
$fromColumnType
===
'SmallInt'
||
$fromColumnType
===
'BigInt'
)
{
if
(
$fromColumnType
instanceof
Types\SmallIntType
||
$fromColumnType
instanceof
Types\BigIntType
)
{
unset
(
$diff
->
changedColumns
[
$oldColumnName
]);
}
}
...
...
@@ -942,17 +943,17 @@ class SqlitePlatform extends AbstractPlatform
}
$field
=
array_merge
([
'unique'
=>
null
,
'autoincrement'
=>
null
,
'default'
=>
null
],
$column
->
toArray
());
$type
=
(
string
)
$field
[
'type'
];
$type
=
$field
[
'type'
];
switch
(
true
)
{
case
isset
(
$field
[
'columnDefinition'
])
||
$field
[
'autoincrement'
]
||
$field
[
'unique'
]
:
case
$type
==
'DateTime'
&&
$field
[
'default'
]
==
$this
->
getCurrentTimestampSQL
()
:
case
$type
==
'Date'
&&
$field
[
'default'
]
==
$this
->
getCurrentDateSQL
()
:
case
$type
==
'Time'
&&
$field
[
'default'
]
==
$this
->
getCurrentTimeSQL
()
:
case
$type
instanceof
Types\DateTimeType
&&
$field
[
'default'
]
==
$this
->
getCurrentTimestampSQL
()
:
case
$type
instanceof
Types\DateType
&&
$field
[
'default'
]
==
$this
->
getCurrentDateSQL
()
:
case
$type
instanceof
Types\TimeType
&&
$field
[
'default'
]
==
$this
->
getCurrentTimeSQL
()
:
return
false
;
}
$field
[
'name'
]
=
$column
->
getQuotedName
(
$this
);
if
(
strtolower
(
$field
[
'type'
])
==
'string'
&&
$field
[
'length'
]
===
null
)
{
if
(
$type
instanceof
Types\StringType
&&
$field
[
'length'
]
===
null
)
{
$field
[
'length'
]
=
255
;
}
...
...
lib/Doctrine/DBAL/Types/BigIntType.php
View file @
ba421d1d
...
...
@@ -27,7 +27,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
* @author robo
* @since 2.0
*/
class
BigIntType
extends
Type
class
BigIntType
extends
Type
implements
PhpIntegerMappingType
{
/**
* {@inheritdoc}
...
...
lib/Doctrine/DBAL/Types/DateTimeType.php
View file @
ba421d1d
...
...
@@ -26,7 +26,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
*
* @since 2.0
*/
class
DateTimeType
extends
Type
class
DateTimeType
extends
Type
implements
PhpDateTimeMappingType
{
/**
* {@inheritdoc}
...
...
lib/Doctrine/DBAL/Types/DateTimeTzType.php
View file @
ba421d1d
...
...
@@ -44,7 +44,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class
DateTimeTzType
extends
Type
class
DateTimeTzType
extends
Type
implements
PhpDateTimeMappingType
{
/**
* {@inheritdoc}
...
...
lib/Doctrine/DBAL/Types/IntegerType.php
View file @
ba421d1d
...
...
@@ -27,7 +27,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
class
IntegerType
extends
Type
class
IntegerType
extends
Type
implements
PhpIntegerMappingType
{
/**
* {@inheritdoc}
...
...
lib/Doctrine/DBAL/Types/PhpDateTimeMappingType.php
0 → 100644
View file @
ba421d1d
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
/**
* Implementations should map a database type to a PHP DateTimeInterface instance.
* @internal
*/
interface
PhpDateTimeMappingType
{
}
lib/Doctrine/DBAL/Types/PhpIntegerMappingType.php
0 → 100644
View file @
ba421d1d
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
/**
* Implementations should map a database type to a PHP integer.
* @internal
*/
interface
PhpIntegerMappingType
{
}
lib/Doctrine/DBAL/Types/SmallIntType.php
View file @
ba421d1d
...
...
@@ -26,7 +26,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
*
* @author robo
*/
class
SmallIntType
extends
Type
class
SmallIntType
extends
Type
implements
PhpIntegerMappingType
{
/**
* {@inheritdoc}
...
...
tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL461Test.php
View file @
ba421d1d
...
...
@@ -3,6 +3,7 @@
namespace
Doctrine\Tests\DBAL\Functional\Ticket
;
use
Doctrine\DBAL\Schema\SQLServerSchemaManager
;
use
Doctrine\DBAL\Types\DecimalType
;
/**
* @group DBAL-461
...
...
@@ -31,6 +32,6 @@ class DBAL461Test extends \PHPUnit\Framework\TestCase
'comment'
=>
null
,
));
self
::
assertEquals
(
'Decimal'
,
(
string
)
$column
->
getType
());
$this
->
assertInstanceOf
(
DecimalType
::
class
,
$column
->
getType
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment