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
7e15665b
Commit
7e15665b
authored
Mar 27, 2014
by
Benjamin Morel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved performance of BlobType & BinaryType
parent
0833d00b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
8 deletions
+56
-8
BinaryType.php
lib/Doctrine/DBAL/Types/BinaryType.php
+4
-1
BlobType.php
lib/Doctrine/DBAL/Types/BlobType.php
+4
-1
BlobTest.php
tests/Doctrine/Tests/DBAL/Types/BlobTest.php
+48
-6
No files found.
lib/Doctrine/DBAL/Types/BinaryType.php
View file @
7e15665b
...
...
@@ -47,7 +47,10 @@ class BinaryType extends Type
}
if
(
is_string
(
$value
))
{
$value
=
fopen
(
'data://text/plain;base64,'
.
base64_encode
(
$value
),
'r'
);
$fp
=
fopen
(
'php://temp'
,
'rb+'
);
fwrite
(
$fp
,
$value
);
fseek
(
$fp
,
0
);
$value
=
$fp
;
}
if
(
!
is_resource
(
$value
))
{
...
...
lib/Doctrine/DBAL/Types/BlobType.php
View file @
7e15665b
...
...
@@ -46,7 +46,10 @@ class BlobType extends Type
}
if
(
is_string
(
$value
))
{
$value
=
fopen
(
'data://text/plain;base64,'
.
base64_encode
(
$value
),
'r'
);
$fp
=
fopen
(
'php://temp'
,
'rb+'
);
fwrite
(
$fp
,
$value
);
fseek
(
$fp
,
0
);
$value
=
$fp
;
}
if
(
!
is_resource
(
$value
))
{
...
...
tests/Doctrine/Tests/DBAL/Types/BlobTest.php
View file @
7e15665b
...
...
@@ -9,18 +9,60 @@ require_once __DIR__ . '/../../TestInit.php';
class
BlobTest
extends
\Doctrine\Tests\DbalTestCase
{
protected
$_platform
,
$_type
;
/**
* @var \Doctrine\Tests\DBAL\Mocks\MockPlatform
*/
protected
$platform
;
/**
* @var \Doctrine\DBAL\Types\BlobType
*/
protected
$type
;
/**
* {@inheritdoc}
*/
protected
function
setUp
()
{
$this
->
_
platform
=
new
\Doctrine\Tests\DBAL\Mocks\MockPlatform
();
$this
->
_
type
=
Type
::
getType
(
'blob'
);
$this
->
platform
=
new
\Doctrine\Tests\DBAL\Mocks\MockPlatform
();
$this
->
type
=
Type
::
getType
(
'blob'
);
}
public
function
testBlobNullConvertsToPHPValue
()
{
$this
->
assertNull
(
$this
->
_type
->
convertToPHPValue
(
null
,
$this
->
_platform
));
$this
->
assertNull
(
$this
->
type
->
convertToPHPValue
(
null
,
$this
->
platform
));
}
public
function
testBinaryStringConvertsToPHPValue
()
{
$databaseValue
=
$this
->
getBinaryString
();
$phpValue
=
$this
->
type
->
convertToPHPValue
(
$databaseValue
,
$this
->
platform
);
$this
->
assertInternalType
(
'resource'
,
$phpValue
);
$this
->
assertSame
(
$databaseValue
,
stream_get_contents
(
$phpValue
));
}
public
function
testBinaryResourceConvertsToPHPValue
()
{
$databaseValue
=
fopen
(
'data://text/plain;base64,'
.
base64_encode
(
$this
->
getBinaryString
()),
'r'
);
$phpValue
=
$this
->
type
->
convertToPHPValue
(
$databaseValue
,
$this
->
platform
);
$this
->
assertSame
(
$databaseValue
,
$phpValue
);
}
/**
* Creates a binary string containing all possible byte values.
*
* @return string
*/
private
function
getBinaryString
()
{
$string
=
''
;
for
(
$i
=
0
;
$i
<
256
;
$i
++
)
{
$string
.=
chr
(
$i
);
}
return
$string
;
}
}
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