-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef61898
commit 7960553
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Types; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
|
||
use function is_resource; | ||
use function restore_error_handler; | ||
use function serialize; | ||
use function set_error_handler; | ||
use function stream_get_contents; | ||
use function unserialize; | ||
|
||
use const E_DEPRECATED; | ||
use const E_USER_DEPRECATED; | ||
|
||
/** | ||
* Type that maps a PHP array to a clob SQL type. | ||
* | ||
* @deprecated Use {@link JsonType} instead. | ||
*/ | ||
class ArrayType extends Type | ||
{ | ||
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string | ||
{ | ||
return $platform->getClobTypeDeclarationSQL($column); | ||
} | ||
|
||
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): mixed | ||
{ | ||
// @todo 3.0 - $value === null check to save real NULL in database | ||
return serialize($value); | ||
} | ||
|
||
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed | ||
{ | ||
if ($value === null) { | ||
return null; | ||
} | ||
|
||
$value = is_resource($value) ? stream_get_contents($value) : $value; | ||
|
||
set_error_handler(function (int $code, string $message): bool { | ||
if ($code === E_DEPRECATED || $code === E_USER_DEPRECATED) { | ||
return false; | ||
} | ||
|
||
throw ConversionException::conversionFailedUnserialization($this->getName(), $message); | ||
}); | ||
|
||
try { | ||
return unserialize($value); | ||
} finally { | ||
restore_error_handler(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
if ( | ||
!is_file(__DIR__ . '/../vendor/doctrine/dbal/src/Types/ArrayType.php') | ||
&& !is_file(__DIR__ . '/../vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/ArrayType.php') | ||
) { | ||
require_once __DIR__ . '/../compatibility/ArrayType.php'; | ||
} |