-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from martin-georgiev/develop
Release v1.0
- Loading branch information
Showing
124 changed files
with
1,022 additions
and
1,112 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 |
---|---|---|
|
@@ -7,8 +7,6 @@ cache: | |
- $HOME/.composer/cache | ||
|
||
php: | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
- 7.2 | ||
- nightly | ||
|
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 |
---|---|---|
@@ -1,13 +1,25 @@ | ||
{ | ||
"name": "martin-georgiev/postgresql-for-doctrine", | ||
"type": "library", | ||
"description": "PostgreSQL enhancements for Doctrine. Provides support for JSONB and array data types and operators and other specific functions.", | ||
"keywords": ["martin georgiev", "doctrine", "postgresql", "postgres", "dbal", "jsonb", "array data types"], | ||
"description": "Adds PostgreSQL 9 and 10 enhancements to Doctrine. Provides support for JSON, JSONB and some array data types. Provides functions, operators and common expressions used when working with JSON data, arrays and features related to text search.", | ||
"keywords": [ | ||
"martin georgiev", | ||
"doctrine", | ||
"postgresql", | ||
"postgres", | ||
"dbal", | ||
"json", | ||
"jsonb", | ||
"text search", | ||
"tsvector", | ||
"array data types" | ||
], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Martin Georgiev", | ||
"email": "[email protected]" | ||
"email": "[email protected]", | ||
"role": "author" | ||
} | ||
], | ||
|
||
|
@@ -23,8 +35,10 @@ | |
}, | ||
|
||
"require": { | ||
"php": "^5.6|^7.0", | ||
"php": "^7.1", | ||
"ext-ctype": "*", | ||
"ext-json": "*", | ||
"ext-mbstring": "*", | ||
"doctrine/dbal": "~2.5", | ||
"doctrine/orm": "~2.5" | ||
}, | ||
|
@@ -34,7 +48,7 @@ | |
"php-coveralls/php-coveralls": "^2.1", | ||
"phpstan/phpstan": "^0.10.2", | ||
"phpstan/phpstan-phpunit": "^0.10", | ||
"phpunit/phpunit": "^5.7|^6.0|^7.0", | ||
"phpunit/phpunit": "^7.0", | ||
"sensiolabs/security-checker": "^4.1" | ||
}, | ||
|
||
|
@@ -49,7 +63,7 @@ | |
"bin/php-cs-fixer fix --config='./.php_cs' --show-progress=none --no-interaction --diff -v" | ||
], | ||
"run-static-analysis": [ | ||
"bin/phpstan analyse --level=5 src/" | ||
"bin/phpstan analyse --level=7 src/" | ||
], | ||
"run-static-analysis-including-tests": [ | ||
"@run-static-analysis", | ||
|
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MartinGeorgiev\Doctrine\DBAL\Types; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
|
@@ -12,18 +14,14 @@ | |
* @since 0.1 | ||
* @author Martin Georgiev <[email protected]> | ||
*/ | ||
abstract class AbstractTypeArray extends AbstractType | ||
abstract class BaseArray extends BaseType | ||
{ | ||
/** | ||
* Converts a value from its PHP representation to its PostgreSql representation of the type. | ||
* | ||
* @param array|null $phpArray The value to convert. | ||
* @param AbstractPlatform $platform The currently used database platform. | ||
* @return string|null The database representation of the value. | ||
* | ||
* @throws ConversionException When passed argument is not PHP array OR When invalid array items are detected | ||
*/ | ||
public function convertToDatabaseValue($phpArray, AbstractPlatform $platform) | ||
public function convertToDatabaseValue($phpArray, AbstractPlatform $platform): ?string | ||
{ | ||
if ($phpArray === null) { | ||
return null; | ||
|
@@ -49,18 +47,15 @@ public function convertToDatabaseValue($phpArray, AbstractPlatform $platform) | |
|
||
/** | ||
* Tests if given PHP array item is from compatible type for PostgreSql | ||
* | ||
* @param mixed $item | ||
* @return bool | ||
*/ | ||
protected function isValidArrayItemForDatabase($item) | ||
protected function isValidArrayItemForDatabase($item): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Transforms PHP array item to a PostgreSql compatible array item | ||
* | ||
* @param mixed $item | ||
* @return mixed | ||
*/ | ||
|
@@ -71,16 +66,19 @@ protected function transformArrayItemForPostgres($item) | |
|
||
/** | ||
* Converts a value from its PostgreSql representation to its PHP representation of this type. | ||
* | ||
* @param mixed $postgresArray The value to convert. | ||
* @param AbstractPlatform $platform The currently used database platform. | ||
* @return array|null The PHP representation of the value. | ||
* @param string|null $postgresArray The value to convert. | ||
*/ | ||
public function convertToPHPValue($postgresArray, AbstractPlatform $platform) | ||
public function convertToPHPValue($postgresArray, AbstractPlatform $platform): ?array | ||
{ | ||
if ($postgresArray === null) { | ||
return null; | ||
} | ||
if (!is_string($postgresArray)) { | ||
$exceptionMessage = 'Given PostgreSql value content type is not PHP string. Instead it is "%s".'; | ||
|
||
throw new ConversionException(sprintf($exceptionMessage, gettype($postgresArray))); | ||
} | ||
|
||
$phpArray = $this->transformPostgresArrayToPHPArray($postgresArray); | ||
foreach ($phpArray as &$item) { | ||
$item = $this->transformArrayItemForPHP($item); | ||
|
@@ -89,23 +87,9 @@ public function convertToPHPValue($postgresArray, AbstractPlatform $platform) | |
return $phpArray; | ||
} | ||
|
||
/** | ||
* Transforms whole PostgreSql array to PHP array | ||
* | ||
* @param string $postgresArray | ||
* @return array | ||
* | ||
* @throws ConversionException When passed argument is not PHP string | ||
*/ | ||
protected function transformPostgresArrayToPHPArray($postgresArray) | ||
protected function transformPostgresArrayToPHPArray(string $postgresArray): array | ||
{ | ||
if (!is_string($postgresArray)) { | ||
$exceptionMessage = 'Given PostgreSql value content type is not PHP string. Instead it is "%s".'; | ||
|
||
throw new ConversionException(sprintf($exceptionMessage, gettype($postgresArray))); | ||
} | ||
|
||
$trimmedPostgresArray = mb_substr($postgresArray, 1, -1); | ||
$trimmedPostgresArray = \mb_substr($postgresArray, 1, -1); | ||
if ($trimmedPostgresArray === '') { | ||
return []; | ||
} | ||
|
@@ -116,7 +100,6 @@ protected function transformPostgresArrayToPHPArray($postgresArray) | |
|
||
/** | ||
* Transforms PostgreSql array item to a PHP compatible array item | ||
* | ||
* @param mixed $item | ||
* @return mixed | ||
*/ | ||
|
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MartinGeorgiev\Doctrine\DBAL\Types; | ||
|
||
use Doctrine\DBAL\Types\ConversionException; | ||
|
@@ -10,22 +12,16 @@ | |
* @since 0.11 | ||
* @author Martin Georgiev <[email protected]> | ||
*/ | ||
abstract class AbstractIntegerArray extends AbstractTypeArray | ||
abstract class BaseIntegerArray extends BaseArray | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
abstract protected function getMinValue(); | ||
abstract protected function getMinValue(): string; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
abstract protected function getMaxValue(); | ||
abstract protected function getMaxValue(): string; | ||
|
||
/** | ||
* {@inheritDoc} | ||
* @param mixed $item | ||
*/ | ||
public function isValidArrayItemForDatabase($item) | ||
public function isValidArrayItemForDatabase($item): bool | ||
{ | ||
return (is_int($item) || is_string($item)) | ||
&& (bool) preg_match('/^-?[0-9]+$/', (string) $item) | ||
|
@@ -34,9 +30,9 @@ public function isValidArrayItemForDatabase($item) | |
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* @param int|string|null $item Whole number | ||
*/ | ||
public function transformArrayItemForPHP($item) | ||
public function transformArrayItemForPHP($item): ?int | ||
{ | ||
if ($item === null) { | ||
return null; | ||
|
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MartinGeorgiev\Doctrine\DBAL\Types; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
|
@@ -11,32 +13,28 @@ | |
* @since 0.1 | ||
* @author Martin Georgiev <[email protected]> | ||
*/ | ||
abstract class AbstractType extends Type | ||
abstract class BaseType extends Type | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) | ||
protected const TYPE_NAME = null; | ||
|
||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string | ||
{ | ||
self::throwExceptionIfTypeNameNotConfigured(); | ||
|
||
return $platform->getDoctrineTypeMapping(constant('static::TYPE_NAME')); | ||
return $platform->getDoctrineTypeMapping(static::TYPE_NAME); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getName() | ||
public function getName(): string | ||
{ | ||
self::throwExceptionIfTypeNameNotConfigured(); | ||
|
||
return constant('static::TYPE_NAME'); | ||
return static::TYPE_NAME; | ||
} | ||
|
||
private static function throwExceptionIfTypeNameNotConfigured() | ||
private static function throwExceptionIfTypeNameNotConfigured(): void | ||
{ | ||
if (false === defined('static::TYPE_NAME')) { | ||
throw new \LogicException(sprintf('Doctrine type defined in class %s is missing the TYPE_NAME constant', self::class)); | ||
if (null === static::TYPE_NAME) { | ||
throw new \LogicException(sprintf('Doctrine type defined in class %s has no meaningful value for TYPE_NAME constant', self::class)); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MartinGeorgiev\Doctrine\DBAL\Types; | ||
|
||
/** | ||
|
@@ -9,25 +11,19 @@ | |
* @since 0.1 | ||
* @author Martin Georgiev <[email protected]> | ||
*/ | ||
class BigIntArray extends AbstractIntegerArray | ||
class BigIntArray extends BaseIntegerArray | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
const TYPE_NAME = 'bigint[]'; | ||
protected const TYPE_NAME = 'bigint[]'; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getMinValue() | ||
protected function getMinValue(): string | ||
{ | ||
return '-9223372036854775807'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getMaxValue() | ||
protected function getMaxValue(): string | ||
{ | ||
return '9223372036854775807'; | ||
} | ||
|
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MartinGeorgiev\Doctrine\DBAL\Types; | ||
|
||
/** | ||
|
@@ -9,25 +11,19 @@ | |
* @since 0.1 | ||
* @author Martin Georgiev <[email protected]> | ||
*/ | ||
class IntegerArray extends AbstractIntegerArray | ||
class IntegerArray extends BaseIntegerArray | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
const TYPE_NAME = 'integer[]'; | ||
protected const TYPE_NAME = 'integer[]'; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getMinValue() | ||
protected function getMinValue(): string | ||
{ | ||
return '-2147483648'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getMaxValue() | ||
protected function getMaxValue(): string | ||
{ | ||
return '2147483647'; | ||
} | ||
|
Oops, something went wrong.