Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made Json type more portable between DBs, started working on StringAr…
…ray for more focused portable string array searching
- Loading branch information
1 parent
1e14b8c
commit e7a53b8
Showing
3 changed files
with
65 additions
and
2 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
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,50 @@ | ||
<?php | ||
|
||
namespace BarnabyWalters\Doctrine\Types; | ||
|
||
use Doctrine\DBAL\Types\Type; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
|
||
/** | ||
* StringArray | ||
* | ||
* @author barnabywalters | ||
*/ | ||
class StringArray extends Type{ | ||
public function getName() { | ||
return 'stringArray'; | ||
} | ||
|
||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { | ||
if ($platform->getName() == 'postgresql') | ||
return 'string[]'; | ||
else | ||
return $platform->getClobTypeDeclarationSQL($fieldDeclaration); | ||
} | ||
|
||
public function convertToDatabaseValue($value, AbstractPlatform $platform) { | ||
if ($platform->getName() == 'postgresql') { | ||
$array = array_map(function ($val) { | ||
return '"' . addslashes((string) $val) . '"'; | ||
}, $value); | ||
|
||
return '{' . join($array, ', ') . '}'; | ||
} else { | ||
$array = array_map(function ($val) { | ||
return (string) $val; | ||
}, $value); | ||
|
||
return json_encode($array); | ||
} | ||
} | ||
|
||
public function convertToPHPValue($value, AbstractPlatform $platform) { | ||
if ($platform->getName() == 'postgresql') { | ||
|
||
} else { | ||
return json_decode($value); | ||
} | ||
} | ||
} | ||
|
||
// EOF |
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