Skip to content

Commit

Permalink
Merge pull request #20 from martin-georgiev/develop
Browse files Browse the repository at this point in the history
Release v0.11
  • Loading branch information
martin-georgiev authored Jul 31, 2018
2 parents 9783b40 + 308bdc3 commit 2920ef9
Show file tree
Hide file tree
Showing 27 changed files with 604 additions and 402 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
build:
environment:
php: '5.6.9'
php: 7.2

coding_style:
php:
Expand Down
91 changes: 53 additions & 38 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,72 @@
language: php

sudo: false

cache:
directories:
- $HOME/.composer/cache

php:
- 5.6
- 7.0
- 7.1
- 7.2
- nightly

env:
global:
- DEPENDENCIES=no
- LATEST_PHP_VERSION="7.2"
matrix:
- DEPENDENCIES="beta"
- DEPENDENCIES="low"
- DEPENDENCIES="stable"

matrix:
include:
- php: 5.6
- php: 5.6
env: DEPENDENCIES=beta
- php: 5.6
env: DEPENDENCIES=low
- php: 7.0
- php: 7.0
env: DEPENDENCIES=beta
- php: 7.0
env: DEPENDENCIES=low
- php: 7.1
- php: 7.1
env: DEPENDENCIES=beta
- php: 7.1
env: DEPENDENCIES=low
- php: 7.2
- php: 7.2
env: DEPENDENCIES=beta
- php: 7.2
env: DEPENDENCIES=low
- php: nightly
fast_finish: true
allow_failures:
- php: nightly
- env: DEPENDENCIES=beta
- env: DEPENDENCIES=low
- env: DEPENDENCIES="beta"
- env: DEPENDENCIES="low"

before_install:
- composer self-update
# Set composer minimum-stability configuration filter to beta versions
- if [ "$DEPENDENCIES" = "beta" ]; then perl -pi -e 's/^}$/,"minimum-stability":"beta"}/' composer.json; fi;
# Disable xdebug, there is no use of it being enabled
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available"
# Prevent Travis throwing an out of memory error
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
# Test if we have a token for github as the project may hit the 60 rph limit
- if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi;
- if [ -n "$GH_TOKEN" ]; then
composer config github-oauth.github.com ${GH_TOKEN};
fi;
- mkdir -p build/logs

install:
- if [ "$DEPENDENCIES" = "no" ]; then composer update; fi;
- if [ "$DEPENDENCIES" = "low" ]; then composer --prefer-lowest --prefer-stable update; fi;
- if [ "$(phpenv version-name)" != "$LATEST_PHP_VERSION" ]; then
composer remove friendsofphp/php-cs-fixer phpstan/phpstan --dev;
fi
- if [ "$DEPENDENCIES" = "beta" ]; then
composer config minimum-stability beta;
composer update -n --prefer-dist;
elif [ "$DEPENDENCIES" = "low" ]; then
composer update -n --prefer-dist --prefer-lowest;
else
composer update -n --prefer-dist;
fi;

script:
- composer validate-files
- composer check-code-style
- composer tests
- if [ "$(phpenv version-name)" != "$LATEST_PHP_VERSION" ]; then
echo "File validation is skipped for older PHP versions";
else
composer validate-files;
fi;
- if [ "$(phpenv version-name)" != "$LATEST_PHP_VERSION" ]; then
echo "Static analysis is skipped for older PHP versions";
else
composer run-static-analysis;
fi;
- if [ "$(phpenv version-name)" != "$LATEST_PHP_VERSION" ]; then
echo "Code style check is skipped for older PHP versions";
else
composer check-code-style;
fi;
- if [ "$(phpenv version-name)" != "$LATEST_PHP_VERSION" ]; then
echo "Security check is skipped for older PHP versions";
else
composer check-security;
fi;
- composer run-tests
51 changes: 48 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/martin-georgiev/postgresql-for-doctrine/badges/quality-score.png)](https://scrutinizer-ci.com/g/martin-georgiev/postgresql-for-doctrine/?branch=master)
[![Build Status](https://api.travis-ci.org/martin-georgiev/postgresql-for-doctrine.svg)](https://www.travis-ci.org/martin-georgiev/postgresql-for-doctrine)
[![Build Status](https://api.travis-ci.org/martin-georgiev/postgresql-for-doctrine.svg?branch=master)](https://www.travis-ci.org/martin-georgiev/postgresql-for-doctrine)
[![Latest Stable Version](https://poser.pugx.org/martin-georgiev/postgresql-for-doctrine/version)](https://packagist.org/packages/martin-georgiev/postgresql-for-doctrine)
[![Total Downloads](https://poser.pugx.org/martin-georgiev/postgresql-for-doctrine/downloads)](https://packagist.org/packages/martin-georgiev/postgresql-for-doctrine)
----
## What's this?
This package provides Doctrine support for some specific PostgreSQL 9.4+ features:
Expand All @@ -19,7 +21,7 @@ Easiest possible way is through [Composer](https://getcomposer.org/download/)
composer require "martin-georgiev/postgresql-for-doctrine=~0.9"

----
## Integration with Symfony 2/3/4
## Integration with Symfony
*Register the new DBAL types*

```yaml
Expand All @@ -42,7 +44,7 @@ doctrine:
doctrine:
dbal:
connections:
your_conenction:
your_connection:
mapping_types:
jsonb: jsonb
jsonb[]: jsonb[]
Expand All @@ -57,6 +59,49 @@ doctrine:
_text: text[]
```
*Register the functions you'll use in your DQL queries*
```yaml
# Usually part of config.yml
doctrine:
orm:
entity_managers:
your_connection:
dql:
string_functions:
ALL_OF: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\All
ANY_OF: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Any
ARRAY_APPEND: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ArrayAppend
ARRAY_CARDINALITY: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ArrayCardinality
ARRAY_CAT: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ArrayCat
ARRAY_LENGTH: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ArrayLength
ARRAY_PREPEND: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ArrayPrepend
ARRAY_REMOVE: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ArrayRemove
ARRAY_REPLACE: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ArrayReplace
ARRAY_TO_STRING: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ArrayToString
ARRAY_TO_JSON: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ArrayToJson
STRING_TO_ARRAY: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\StringToArray
CONTAINS: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Contains
OVERLAPS: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Overlaps
GREATEST: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Greatest
LEAST: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Least
IN_ARRAY: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\InArray
IS_CONTAINED_BY: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\IsContainedBy
JSON_GET_FIELD: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonGetField
JSON_GET_FIELD_AS_TEXT: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonGetFieldAsText
JSON_GET_FIELD_AS_INTEGER: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonGetFieldAsInteger
JSON_GET_OBJECT: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonGetObject
JSON_GET_OBJECT_AS_TEXT: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonGetObjectAsText
JSON_GET_OBJECT_AS_INTEGER: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonGetObjectAsInteger
JSONB_ARRAY_LENGTH: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonbArrayLength
JSONB_EACH: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonbEach
JSONB_EACH_TEXT: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonbEachText
JSONB_EXISTS: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonbExists
JSONB_INSERT: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonbInsert
JSONB_OBJECT_KEYS: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonbObjectKeys
JSONB_SET: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonbSet
```
## Integration with Laravel 5
Unfortunately, Laravel still doesn't come with native Doctrine2 integration.
The steps below are based on integration with [Laravel Doctrine](http://www.laraveldoctrine.org/).
Expand Down
51 changes: 33 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,15 @@
"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", "doctrine2", "postgresql", "postgres", "dbal", "jsonb", "array data types"],
"minimum-stability": "stable",
"keywords": ["martin georgiev", "doctrine", "postgresql", "postgres", "dbal", "jsonb", "array data types"],
"license": "MIT",
"authors": [
{
"name": "Martin Georgiev",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.5",
"doctrine/dbal": "~2.5",
"doctrine/orm": "~2.5"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "*",
"jakub-onderka/php-parallel-lint": "^0.9.2",
"phpunit/phpunit": "~5.0",
"sensiolabs/security-checker": "^4.1"
},

"autoload": {
"psr-4": {
"MartinGeorgiev\\": "src/MartinGeorgiev/"
Expand All @@ -32,26 +21,52 @@
"MartinGeorgiev\\Tests\\": "tests/MartinGeorgiev/"
}
},

"require": {
"php": ">=5.6",
"doctrine/dbal": "~2.5",
"doctrine/orm": "~2.5"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "*",
"jakub-onderka/php-parallel-lint": "^1.0",
"phpstan/phpstan": "^0.10.2",
"phpunit/phpunit": "^5.7",
"sensiolabs/security-checker": "^4.1"
},

"scripts": {
"check-code-style": [
"vendor/bin/php-cs-fixer fix --config='./.php_cs' --show-progress=none --dry-run --no-interaction -v"
"bin/php-cs-fixer fix --config='./.php_cs' --show-progress=none --dry-run --no-interaction --diff -v"
],
"check-security": [
"bin/security-checker security:check"
],
"fix-code-style": [
"vendor/bin/php-cs-fixer fix --config='./.php_cs' --show-progress=none --no-interaction -v"
"bin/php-cs-fixer fix --config='./.php_cs' --show-progress=none --no-interaction --diff -v"
],
"run-static-analysis": [
"bin/phpstan analyse --level=3 src/"
],
"run-static-analysis-including-tests": [
"@run-static-analysis",
"bin/phpstan analyse --level=3 tests/"
],
"tests": [
"vendor/bin/phpunit"
"run-tests": [
"bin/phpunit"
],
"validate-files": [
"vendor/bin/parallel-lint --exclude vendor ."
"bin/parallel-lint --exclude vendor --exclude bin ."
]
},

"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"config": {
"bin-dir": "bin",
"sort-packages": true
},
"prefer-stable": true
Expand Down
54 changes: 54 additions & 0 deletions src/MartinGeorgiev/Doctrine/DBAL/Types/AbstractIntegerArray.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace MartinGeorgiev\Doctrine\DBAL\Types;

use Doctrine\DBAL\Types\ConversionException;

/**
* @see https://www.postgresql.org/docs/9.4/static/arrays.html
*
* @since 0.11
* @author Martin Georgiev <[email protected]>
*/
abstract class AbstractIntegerArray extends AbstractTypeArray
{
/**
* @return string
*/
abstract protected function getMinValue();

/**
* @return string
*/
abstract protected function getMaxValue();

/**
* {@inheritDoc}
*/
public function isValidArrayItemForDatabase($item)
{
return (is_int($item) || is_string($item))
&& (bool) preg_match('/^-?[0-9]+$/', (string) $item)
&& (string) $item >= $this->getMinValue()
&& (string) $item <= $this->getMaxValue();
}

/**
* {@inheritDoc}
*/
public function transformArrayItemForPHP($item)
{
if ($item === null) {
return null;
}

$isInvalidPHPInt = (bool) preg_match('/^-?[0-9]+$/', (string) $item) === false
|| (string) $item < $this->getMinValue()
|| (string) $item > $this->getMaxValue();
if ($isInvalidPHPInt) {
throw new ConversionException(sprintf('Given value of %s content cannot be transformed to valid PHP integer.', var_export($item, true)));
}

return (int) $item;
}
}
15 changes: 13 additions & 2 deletions src/MartinGeorgiev/Doctrine/DBAL/Types/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,25 @@ abstract class AbstractType extends Type
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getDoctrineTypeMapping(static::TYPE_NAME);
self::throwExceptionIfTypeNameNotConfigured();

return $platform->getDoctrineTypeMapping(constant('static::TYPE_NAME'));
}

/**
* {@inheritDoc}
*/
public function getName()
{
return static::TYPE_NAME;
self::throwExceptionIfTypeNameNotConfigured();

return constant('static::TYPE_NAME');
}

private static function throwExceptionIfTypeNameNotConfigured()
{
if (false === defined('static::TYPE_NAME')) {
throw new \LogicException(sprintf('Doctrine type defined in class %s is missing the TYPE_NAME constant', self::class));
}
}
}
Loading

0 comments on commit 2920ef9

Please sign in to comment.