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
1ca9db4f
Commit
1ca9db4f
authored
Jun 26, 2012
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move Doctrine Type requires SQL comment detection from AbstractPlatform directly into the Types.
parent
cf503ec1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
119 additions
and
69 deletions
+119
-69
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+8
-1
ArrayType.php
lib/Doctrine/DBAL/Types/ArrayType.php
+7
-0
JsonArrayType.php
lib/Doctrine/DBAL/Types/JsonArrayType.php
+41
-34
ObjectType.php
lib/Doctrine/DBAL/Types/ObjectType.php
+7
-0
SimpleArrayType.php
lib/Doctrine/DBAL/Types/SimpleArrayType.php
+41
-34
Type.php
lib/Doctrine/DBAL/Types/Type.php
+15
-0
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
1ca9db4f
...
...
@@ -323,7 +323,14 @@ abstract class AbstractPlatform
*/
protected
function
initializeCommentedDoctrineTypes
()
{
$this
->
doctrineTypeComments
=
array
(
Type
::
TARRAY
,
Type
::
SIMPLE_ARRAY
,
Type
::
JSON_ARRAY
,
Type
::
OBJECT
);
$this
->
doctrineTypeComments
=
array
();
foreach
(
Type
::
getTypesMap
()
as
$typeName
=>
$className
)
{
$type
=
Type
::
getType
(
$typeName
);
if
(
$type
->
requiresSQLCommentHint
(
$this
))
{
$this
->
doctrineTypeComments
[]
=
$typeName
;
}
}
}
/**
...
...
lib/Doctrine/DBAL/Types/ArrayType.php
View file @
1ca9db4f
...
...
@@ -19,6 +19,8 @@
namespace
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
/**
* Type that maps a PHP array to a clob SQL type.
*
...
...
@@ -54,4 +56,9 @@ class ArrayType extends Type
{
return
Type
::
TARRAY
;
}
public
function
requiresSQLCommentHint
(
AbstractPlatform
$platform
)
{
return
true
;
}
}
lib/Doctrine/DBAL/Types/JsonArrayType.php
View file @
1ca9db4f
<?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>.
/*
* 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
;
/**
* Array Type which can be used to generate json arrays.
*
...
...
@@ -27,33 +29,38 @@ namespace Doctrine\DBAL\Types;
*/
class
JsonArrayType
extends
Type
{
public
function
getSQLDeclaration
(
array
$fieldDeclaration
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
$platform
->
getClobTypeDeclarationSQL
(
$fieldDeclaration
);
public
function
getSQLDeclaration
(
array
$fieldDeclaration
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
$platform
->
getClobTypeDeclarationSQL
(
$fieldDeclaration
);
}
public
function
convertToDatabaseValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
public
function
convertToDatabaseValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
if
(
null
===
$value
)
{
return
null
;
}
return
json_encode
(
$value
);
}
public
function
convertToPHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
if
(
$value
===
null
)
{
return
array
();
}
return
json_encode
(
$value
);
}
public
function
convertToPHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
if
(
$value
===
null
)
{
return
array
();
}
$value
=
(
is_resource
(
$value
))
?
stream_get_contents
(
$value
)
:
$value
;
return
json_decode
(
$value
,
true
);
}
public
function
getName
()
{
return
Type
::
JSON_ARRAY
;
}
public
function
getName
()
{
return
Type
::
JSON_ARRAY
;
}
public
function
requiresSQLCommentHint
(
AbstractPlatform
$platform
)
{
return
true
;
}
}
lib/Doctrine/DBAL/Types/ObjectType.php
View file @
1ca9db4f
...
...
@@ -19,6 +19,8 @@
namespace
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
/**
* Type that maps a PHP object to a clob SQL type.
*
...
...
@@ -54,4 +56,9 @@ class ObjectType extends Type
{
return
Type
::
OBJECT
;
}
public
function
requiresSQLCommentHint
(
AbstractPlatform
$platform
)
{
return
true
;
}
}
lib/Doctrine/DBAL/Types/SimpleArrayType.php
View file @
1ca9db4f
<?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>.
/*
* 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
;
/**
* Array Type which can be used for simple values.
*
...
...
@@ -29,33 +31,38 @@ namespace Doctrine\DBAL\Types;
*/
class
SimpleArrayType
extends
Type
{
public
function
getSQLDeclaration
(
array
$fieldDeclaration
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
$platform
->
getClobTypeDeclarationSQL
(
$fieldDeclaration
);
public
function
getSQLDeclaration
(
array
$fieldDeclaration
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
$platform
->
getClobTypeDeclarationSQL
(
$fieldDeclaration
);
}
public
function
convertToDatabaseValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
public
function
convertToDatabaseValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
if
(
!
$value
)
{
return
null
;
}
return
implode
(
','
,
$value
);
}
public
function
convertToPHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
if
(
$value
===
null
)
{
return
array
();
}
return
implode
(
','
,
$value
);
}
public
function
convertToPHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
if
(
$value
===
null
)
{
return
array
();
}
$value
=
(
is_resource
(
$value
))
?
stream_get_contents
(
$value
)
:
$value
;
return
explode
(
','
,
$value
);
}
public
function
getName
()
{
return
Type
::
SIMPLE_ARRAY
;
}
public
function
getName
()
{
return
Type
::
SIMPLE_ARRAY
;
}
public
function
requiresSQLCommentHint
(
AbstractPlatform
$platform
)
{
return
true
;
}
}
lib/Doctrine/DBAL/Types/Type.php
View file @
1ca9db4f
...
...
@@ -288,4 +288,19 @@ abstract class Type
{
return
array
();
}
/**
* If this Doctrine Type maps to an already mapped database type,
* reverse schema engineering can't take them apart. You need to mark
* one of those types as commented, which will have Doctrine use an SQL
* comment to typehint the actual Doctrine Type.
*
* @param AbstractPlatform $platform
* @return bool
*/
public
function
requiresSQLCommentHint
(
AbstractPlatform
$platform
)
{
return
false
;
}
}
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