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
Hide 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
...
...
@@ -707,6 +707,60 @@ class PostgreSqlPlatform extends AbstractPlatform
return
$sql
;
}
/**
* Converts a single boolean value.
*
* 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
*/
private
function
convertSingleBooleanValue
(
$value
,
$callback
)
{
if
(
null
===
$value
)
{
return
$callback
(
false
);
}
if
(
is_bool
(
$value
)
||
is_numeric
(
$value
))
{
return
$callback
(
$value
?
true
:
false
);
}
if
(
is_string
(
$value
)
&&
in_array
(
trim
(
strtolower
(
$value
)),
$this
->
booleanLiterals
[
'false'
]))
{
return
$callback
(
false
);
}
return
$callback
(
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
);
}
/**
* {@inheritDoc}
*
...
...
@@ -718,31 +772,12 @@ class PostgreSqlPlatform extends AbstractPlatform
return
parent
::
convertBooleans
(
$item
);
}
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'
;
}
}
}
}
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'
;
}
return
$this
->
doConvertBooleans
(
$item
,
function
(
$boolean
)
{
return
true
===
$boolean
?
'true'
:
'false'
;
}
}
return
$item
;
);
}
/**
...
...
@@ -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
$item
;
return
$this
->
doConvertBooleans
(
$item
,
function
(
$boolean
)
{
return
(
int
)
$boolean
;
}
);
}
/**
...
...
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