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
d2995659
Commit
d2995659
authored
Apr 23, 2014
by
Davi Koscianski Vidal
Committed by
lucasvanlierop
Jun 30, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improving conversion using @deeky666 idea
parent
08b83087
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
37 deletions
+65
-37
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+65
-37
No files found.
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
d2995659
...
...
@@ -708,41 +708,76 @@ class PostgreSqlPlatform extends AbstractPlatform
}
/**
*
{@inheritDoc}
*
Converts a single boolean value.
*
* Postgres wants boolean values converted to the strings 'true'/'false'.
* First converts the value to its native PHP boolean type
* and passes it to the given callback function to be reconverted
* into any custom representation.
*
* @param mixed $value The value to convert.
* @param callable $callback The callback function to use for converting the real boolean value.
*
* @return mixed
*/
p
ublic
function
convertBooleans
(
$item
)
p
rivate
function
convertSingleBooleanValue
(
$value
,
$callback
)
{
if
(
!
$this
->
useBooleanTrueFalseStrings
)
{
return
parent
::
convertBooleans
(
$item
);
if
(
null
===
$value
)
{
return
$callback
(
false
);
}
if
(
is_array
(
$item
))
{
foreach
(
$item
as
$key
=>
$value
)
{
if
(
is_bool
(
$value
)
||
is_numeric
(
$value
))
{
$item
[
$key
]
=
(
$value
)
?
'true'
:
'false'
;
}
elseif
(
is_string
(
$value
))
{
if
(
in_array
(
trim
(
strtolower
(
$value
)),
$this
->
booleanLiterals
[
'false'
]))
{
$item
[
$key
]
=
'false'
;
}
else
{
$item
[
$key
]
=
'true'
;
return
$callback
(
$value
?
true
:
false
);
}
if
(
is_string
(
$value
)
&&
in_array
(
trim
(
strtolower
(
$value
)),
$this
->
booleanLiterals
[
'false'
]))
{
return
$callback
(
false
);
}
return
$callback
(
true
);
}
}
else
{
if
(
is_bool
(
$item
)
||
is_numeric
(
$item
))
{
$item
=
(
$item
)
?
'true'
:
'false'
;
}
elseif
(
is_string
(
$item
))
{
if
(
in_array
(
trim
(
strtolower
(
$item
)),
$this
->
booleanLiterals
[
'false'
]))
{
$item
=
'false'
;
}
else
{
$item
=
'true'
;
/**
* Converts one or multiple boolean values.
*
* First converts the value(s) to their native PHP boolean type
* and passes them to the given callback function to be reconverted
* into any custom representation.
*
* @param $item The value(s) to convert.
* @param $callback The callback function to use for converting the real boolean value(s).
*
* @return mixed
*/
private
function
doConvertBooleans
(
$item
,
$callback
)
{
if
(
is_array
(
$item
))
{
foreach
(
$item
as
$key
=>
$value
)
{
$item
[
$key
]
=
$this
->
convertSingleBooleanValue
(
$value
,
$callback
);
}
return
$item
;
}
return
$this
->
convertSingleBooleanValue
(
$item
,
$callback
);
}
return
$item
;
/**
* {@inheritDoc}
*
* Postgres wants boolean values converted to the strings 'true'/'false'.
*/
public
function
convertBooleans
(
$item
)
{
if
(
!
$this
->
useBooleanTrueFalseStrings
)
{
return
parent
::
convertBooleans
(
$item
);
}
return
$this
->
doConvertBooleans
(
$item
,
function
(
$boolean
)
{
return
true
===
$boolean
?
'true'
:
'false'
;
}
);
}
/**
...
...
@@ -754,19 +789,12 @@ class PostgreSqlPlatform extends AbstractPlatform
return
parent
::
convertBooleansToDatabaseValue
(
$item
);
}
$item
=
$this
->
convertBooleans
(
$item
);
if
(
is_array
(
$item
))
{
$item
=
array_map
(
function
(
$element
)
{
return
(
int
)
(
'true'
===
$element
);
},
$item
);
}
else
{
$item
=
(
int
)
(
'true'
===
$item
);
return
$this
->
doConvertBooleans
(
$item
,
function
(
$boolean
)
{
return
(
int
)
$boolean
;
}
return
$item
;
);
}
/**
...
...
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