From 774582bb31025581abbc57593d9fb3f72722ad61 Mon Sep 17 00:00:00 2001 From: Artem Genvald Date: Fri, 11 Apr 2014 10:23:08 +0300 Subject: [PATCH 1/6] Remove BitDeli badge. It doesn't work anymore :( --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 7f32eea..18f1d8d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ Provides support of *MySQL* **ENUM type** for Doctrine in Symfony applications [![Dependency Status](https://www.versioneye.com/user/projects/52ea10b1ec13755c2f000045/badge.png)](https://www.versioneye.com/user/projects/52ea10b1ec13755c2f000045) [![Total Downloads](https://poser.pugx.org/fresh/doctrine-enum-bundle/downloads.png)](https://packagist.org/packages/fresh/doctrine-enum-bundle) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/0cff4816-374a-474e-a1d5-9d5db34562e3/mini.png)](https://insight.sensiolabs.com/projects/0cff4816-374a-474e-a1d5-9d5db34562e3) -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/fre5h/doctrineenumbundle/trend.png)](https://bitdeli.com/free "Bitdeli Badge") [![knpbundles.com](http://knpbundles.com/fre5h/DoctrineEnumBundle/badge-short)](http://knpbundles.com/fre5h/DoctrineEnumBundle) From 2992d2949ea02e916067049452690d3df1022230 Mon Sep 17 00:00:00 2001 From: Artem Genvald Date: Sun, 3 Aug 2014 11:44:49 +0300 Subject: [PATCH 2/6] Add reference badge --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 18f1d8d..a0eed69 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ Provides support of *MySQL* **ENUM type** for Doctrine in Symfony applications [![Build Status](https://secure.travis-ci.org/fre5h/DoctrineEnumBundle.png?branch=master)](https://travis-ci.org/fre5h/DoctrineEnumBundle) [![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/fre5h/DoctrineEnumBundle/badges/quality-score.png?s=be81f9b30a3996e7786cff5b4e0c0d972a64a37b)](https://scrutinizer-ci.com/g/fre5h/DoctrineEnumBundle/) [![Latest Stable Version](https://poser.pugx.org/fresh/doctrine-enum-bundle/v/stable.png)](https://packagist.org/packages/fresh/doctrine-enum-bundle) -[![Dependency Status](https://www.versioneye.com/user/projects/52ea10b1ec13755c2f000045/badge.png)](https://www.versioneye.com/user/projects/52ea10b1ec13755c2f000045) +[![Dependency Status](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/5.3.x-dev/badge.svg)](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/5.3.x-dev) +[![Reference Status](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/reference_badge.svg?style=flat)](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/references) [![Total Downloads](https://poser.pugx.org/fresh/doctrine-enum-bundle/downloads.png)](https://packagist.org/packages/fresh/doctrine-enum-bundle) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/0cff4816-374a-474e-a1d5-9d5db34562e3/mini.png)](https://insight.sensiolabs.com/projects/0cff4816-374a-474e-a1d5-9d5db34562e3) From 5d907985a24905c162f4138ce2a5470a533168cd Mon Sep 17 00:00:00 2001 From: Artem Genvald Date: Sun, 3 Aug 2014 11:56:57 +0300 Subject: [PATCH 3/6] Update badges --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a0eed69..492079a 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,11 @@ Provides support of *MySQL* **ENUM type** for Doctrine in Symfony applications [![Build Status](https://secure.travis-ci.org/fre5h/DoctrineEnumBundle.png?branch=master)](https://travis-ci.org/fre5h/DoctrineEnumBundle) [![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/fre5h/DoctrineEnumBundle/badges/quality-score.png?s=be81f9b30a3996e7786cff5b4e0c0d972a64a37b)](https://scrutinizer-ci.com/g/fre5h/DoctrineEnumBundle/) [![Latest Stable Version](https://poser.pugx.org/fresh/doctrine-enum-bundle/v/stable.png)](https://packagist.org/packages/fresh/doctrine-enum-bundle) -[![Dependency Status](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/5.3.x-dev/badge.svg)](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/5.3.x-dev) -[![Reference Status](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/reference_badge.svg?style=flat)](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/references) [![Total Downloads](https://poser.pugx.org/fresh/doctrine-enum-bundle/downloads.png)](https://packagist.org/packages/fresh/doctrine-enum-bundle) -[![SensioLabsInsight](https://insight.sensiolabs.com/projects/0cff4816-374a-474e-a1d5-9d5db34562e3/mini.png)](https://insight.sensiolabs.com/projects/0cff4816-374a-474e-a1d5-9d5db34562e3) +[![Dependency Status](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/badge.svg)](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/5.3.x-dev) +[![Reference Status](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/reference_badge.svg)](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/references) + +[![SensioLabsInsight](https://insight.sensiolabs.com/projects/0cff4816-374a-474e-a1d5-9d5db34562e3/big.png)](https://insight.sensiolabs.com/projects/0cff4816-374a-474e-a1d5-9d5db34562e3) [![knpbundles.com](http://knpbundles.com/fre5h/DoctrineEnumBundle/badge-short)](http://knpbundles.com/fre5h/DoctrineEnumBundle) From 2a11eb65666356f9293c7a628b828627c6f99d49 Mon Sep 17 00:00:00 2001 From: Artem Genvald Date: Thu, 7 Aug 2014 11:25:13 +0300 Subject: [PATCH 4/6] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 194577f..31064d7 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "fresh/doctrine-enum-bundle", - "description": "Provides support of MySQL ENUM type for Doctrine2 in Symfony2 applications.", - "keywords": ["bundle", "symfony", "doctrine", "entity", "enum", "type", "DBAL"], + "description": "Provides support of ENUM type for Doctrine2 in Symfony2 applications.", + "keywords": ["bundle", "symfony", "doctrine", "entity", "enum", "type", "DBAL", "MySQL", "SQLite"], "homepage": "https://github.com/fre5h/DoctrineEnumBundle", "type": "symfony-bundle", From 5064046b306ddd514a8094bb2a1a65ae039a42af Mon Sep 17 00:00:00 2001 From: Artem Genvald Date: Thu, 7 Aug 2014 11:26:42 +0300 Subject: [PATCH 5/6] Update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 492079a..f0e1199 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ # DoctrineEnumBundle -Provides support of *MySQL* **ENUM type** for Doctrine in Symfony applications +Provides support of **ENUM type** for Doctrine in Symfony applications + +## Supported platforms: + +* MySQL +* SQLite [![License](https://poser.pugx.org/fresh/doctrine-enum-bundle/license.png)](https://packagist.org/packages/fresh/doctrine-enum-bundle) [![Build Status](https://secure.travis-ci.org/fre5h/DoctrineEnumBundle.png?branch=master)](https://travis-ci.org/fre5h/DoctrineEnumBundle) From e0ecb83ee4d8fb08923d21ca59d56b3adb6a400f Mon Sep 17 00:00:00 2001 From: Artem Genvald Date: Thu, 7 Aug 2014 11:28:31 +0300 Subject: [PATCH 6/6] Refactoring --- .scrutinizer.yml | 2 + .travis.yml | 9 +-- DBAL/Types/AbstractEnumType.php | 19 +++--- .../FreshDoctrineEnumExtension.php | 18 ++---- .../EnumTypeIsNotRegisteredException.php | 2 +- ...egisteredButClassDoesNotExistException.php | 2 +- Exception/NoRegisteredEnumTypesException.php | 2 +- ...FoundInFewRegisteredEnumTypesException.php | 2 +- ...tFoundInAnyRegisteredEnumTypeException.php | 2 +- .../DBAL/Types/BasketballPositionType.php | 4 +- Fixtures/DBAL/Types/MapLocationType.php | 4 +- Form/EnumTypeGuesser.php | 8 +-- FreshDoctrineEnumBundle.php | 2 +- README.md | 59 ++++++++----------- Resources/config/services.xml | 19 ------ Resources/config/services.yml | 16 +++++ Tests/DBAL/Types/AbstractEnumTypeTest.php | 32 +++++----- .../ReadableEnumValueExtensionTest.php | 22 +++---- Tests/Validator/EnumValidatorTest.php | 25 ++++---- Twig/Extension/ReadableEnumValueExtension.php | 22 +++---- Validator/Constraints/Enum.php | 4 +- Validator/Constraints/EnumValidator.php | 6 +- composer.json | 26 ++++---- phpunit.xml => phpunit.xml.dist | 0 24 files changed, 150 insertions(+), 157 deletions(-) delete mode 100644 Resources/config/services.xml create mode 100644 Resources/config/services.yml rename phpunit.xml => phpunit.xml.dist (100%) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 83dcd33..2e432cc 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -27,3 +27,5 @@ tools: php_pdepend: excluded_dirs: ["vendor"] php_loc: true + php_analyzer: true + sensiolabs_security_checker: true diff --git a/.travis.yml b/.travis.yml index fc50b27..e3cf95a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,15 +3,16 @@ language: php php: - 5.4 - 5.5 + - 5.6 before_script: - - composer install + - composer install --dev - pear install --alldeps PHP_CodeSniffer - phpenv rehash - - git clone git://github.com/opensky/Symfony2-coding-standard.git $(pear config-get php_dir)/PHP/CodeSniffer/Standards/Symfony2 - - phpcs --standard=Symfony2 --ignore=/vendor ./ -script: phpunit +script: + - phpunit + - phpcs --standard=PSR2 --ignore=/vendor ./ notifications: email: diff --git a/DBAL/Types/AbstractEnumType.php b/DBAL/Types/AbstractEnumType.php index 272e854..cc69971 100644 --- a/DBAL/Types/AbstractEnumType.php +++ b/DBAL/Types/AbstractEnumType.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle\DBAL\Types; +namespace Fresh\DoctrineEnumBundle\DBAL\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; @@ -30,7 +30,7 @@ abstract class AbstractEnumType extends Type protected $name = ''; /** - * @var array Array of ENUM Values, where enum values are keys and their readable versions are values + * @var array Array of ENUM Values, where ENUM values are keys and their readable versions are values * @static */ protected static $choices = []; @@ -56,12 +56,15 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { - $values = implode(', ', array_map( - function ($value) { - return "'{$value}'"; - }, - $this->getValues() - )); + $values = implode( + ', ', + array_map( + function ($value) { + return "'{$value}'"; + }, + $this->getValues() + ) + ); if ($platform instanceof SqlitePlatform) { return sprintf('TEXT CHECK(%s IN (%s))', $fieldDeclaration['name'], $values); diff --git a/DependencyInjection/FreshDoctrineEnumExtension.php b/DependencyInjection/FreshDoctrineEnumExtension.php index 959af60..3e07c8a 100644 --- a/DependencyInjection/FreshDoctrineEnumExtension.php +++ b/DependencyInjection/FreshDoctrineEnumExtension.php @@ -8,11 +8,11 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle\DependencyInjection; +namespace Fresh\DoctrineEnumBundle\DependencyInjection; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\HttpKernel\DependencyInjection\Extension; /** @@ -30,17 +30,7 @@ class FreshDoctrineEnumExtension extends Extension */ public function load(array $configs, ContainerBuilder $container) { - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); - $loader->load('services.xml'); - } - - /** - * Get alias - * - * @return string - */ - public function getAlias() - { - return 'fresh_doctrine_enum'; + $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader->load('services.yml'); } } diff --git a/Exception/EnumTypeIsNotRegisteredException.php b/Exception/EnumTypeIsNotRegisteredException.php index b450afa..8d39242 100644 --- a/Exception/EnumTypeIsNotRegisteredException.php +++ b/Exception/EnumTypeIsNotRegisteredException.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle\Exception; +namespace Fresh\DoctrineEnumBundle\Exception; /** * EnumTypeIsNotRegisteredException diff --git a/Exception/EnumTypeIsRegisteredButClassDoesNotExistException.php b/Exception/EnumTypeIsRegisteredButClassDoesNotExistException.php index ac6a9a4..493e27b 100644 --- a/Exception/EnumTypeIsRegisteredButClassDoesNotExistException.php +++ b/Exception/EnumTypeIsRegisteredButClassDoesNotExistException.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle\Exception; +namespace Fresh\DoctrineEnumBundle\Exception; /** * EnumTypeIsRegisteredButClassDoesNotExistException diff --git a/Exception/NoRegisteredEnumTypesException.php b/Exception/NoRegisteredEnumTypesException.php index 5cb2c16..4a8745d 100644 --- a/Exception/NoRegisteredEnumTypesException.php +++ b/Exception/NoRegisteredEnumTypesException.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle\Exception; +namespace Fresh\DoctrineEnumBundle\Exception; /** * NoRegisteredEnumTypesException diff --git a/Exception/ValueIsFoundInFewRegisteredEnumTypesException.php b/Exception/ValueIsFoundInFewRegisteredEnumTypesException.php index c8cd67f..b14f988 100644 --- a/Exception/ValueIsFoundInFewRegisteredEnumTypesException.php +++ b/Exception/ValueIsFoundInFewRegisteredEnumTypesException.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle\Exception; +namespace Fresh\DoctrineEnumBundle\Exception; /** * ValueIsFoundInFewRegisteredEnumTypesException diff --git a/Exception/ValueIsNotFoundInAnyRegisteredEnumTypeException.php b/Exception/ValueIsNotFoundInAnyRegisteredEnumTypeException.php index dbe90e4..434e40c 100644 --- a/Exception/ValueIsNotFoundInAnyRegisteredEnumTypeException.php +++ b/Exception/ValueIsNotFoundInAnyRegisteredEnumTypeException.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle\Exception; +namespace Fresh\DoctrineEnumBundle\Exception; /** * ValueIsNotFoundInAnyRegisteredEnumTypeException diff --git a/Fixtures/DBAL/Types/BasketballPositionType.php b/Fixtures/DBAL/Types/BasketballPositionType.php index e09a291..7944f71 100644 --- a/Fixtures/DBAL/Types/BasketballPositionType.php +++ b/Fixtures/DBAL/Types/BasketballPositionType.php @@ -8,9 +8,9 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle\Fixtures\DBAL\Types; +namespace Fresh\DoctrineEnumBundle\Fixtures\DBAL\Types; -use Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType; +use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType; /** * Basketball position type diff --git a/Fixtures/DBAL/Types/MapLocationType.php b/Fixtures/DBAL/Types/MapLocationType.php index ddc10d9..ac060e6 100644 --- a/Fixtures/DBAL/Types/MapLocationType.php +++ b/Fixtures/DBAL/Types/MapLocationType.php @@ -8,9 +8,9 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle\Fixtures\DBAL\Types; +namespace Fresh\DoctrineEnumBundle\Fixtures\DBAL\Types; -use Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType; +use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType; /** * Map location type diff --git a/Form/EnumTypeGuesser.php b/Form/EnumTypeGuesser.php index bc640a0..a3b704b 100644 --- a/Form/EnumTypeGuesser.php +++ b/Form/EnumTypeGuesser.php @@ -8,11 +8,11 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle\Form; +namespace Fresh\DoctrineEnumBundle\Form; use Doctrine\Common\Persistence\ManagerRegistry; -use Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType; -use Fresh\Bundle\DoctrineEnumBundle\Exception\EnumTypeIsRegisteredButClassDoesNotExistException; +use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType; +use Fresh\DoctrineEnumBundle\Exception\EnumTypeIsRegisteredButClassDoesNotExistException; use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser; use Symfony\Component\Form\Guess\Guess; use Symfony\Component\Form\Guess\TypeGuess; @@ -76,7 +76,7 @@ public function guessType($class, $property) $enumTypeFullClassName = $this->registeredEnumTypes[$fieldType]; - $abstractEnumTypeFullClassName = 'Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType'; + $abstractEnumTypeFullClassName = 'Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType'; if (get_parent_class($enumTypeFullClassName) !== $abstractEnumTypeFullClassName) { return null; diff --git a/FreshDoctrineEnumBundle.php b/FreshDoctrineEnumBundle.php index 7517001..6b5da3b 100644 --- a/FreshDoctrineEnumBundle.php +++ b/FreshDoctrineEnumBundle.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle; +namespace Fresh\DoctrineEnumBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; diff --git a/README.md b/README.md index f0e1199..a7c4f99 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,36 @@ # DoctrineEnumBundle -Provides support of **ENUM type** for Doctrine in Symfony applications +Provides support of **ENUM type** for Doctrine in Symfony applications. -## Supported platforms: - -* MySQL -* SQLite - -[![License](https://poser.pugx.org/fresh/doctrine-enum-bundle/license.png)](https://packagist.org/packages/fresh/doctrine-enum-bundle) -[![Build Status](https://secure.travis-ci.org/fre5h/DoctrineEnumBundle.png?branch=master)](https://travis-ci.org/fre5h/DoctrineEnumBundle) -[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/fre5h/DoctrineEnumBundle/badges/quality-score.png?s=be81f9b30a3996e7786cff5b4e0c0d972a64a37b)](https://scrutinizer-ci.com/g/fre5h/DoctrineEnumBundle/) +* Scrutinizer [![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/fre5h/DoctrineEnumBundle/badges/quality-score.png?s=be81f9b30a3996e7786cff5b4e0c0d972a64a37b)](https://scrutinizer-ci.com/g/fre5h/DoctrineEnumBundle/) +[![Build Status](https://scrutinizer-ci.com/g/fre5h/delivery-auto-api-php-client/badges/build.png?b=master)](https://scrutinizer-ci.com/g/fre5h/delivery-auto-api-php-client/build-status/master) +* Travis CI [![Build Status](https://secure.travis-ci.org/fre5h/DoctrineEnumBundle.png?branch=master)](https://travis-ci.org/fre5h/DoctrineEnumBundle) +* Packagist.org [![License](https://poser.pugx.org/fresh/doctrine-enum-bundle/license.png)](https://packagist.org/packages/fresh/doctrine-enum-bundle) [![Latest Stable Version](https://poser.pugx.org/fresh/doctrine-enum-bundle/v/stable.png)](https://packagist.org/packages/fresh/doctrine-enum-bundle) [![Total Downloads](https://poser.pugx.org/fresh/doctrine-enum-bundle/downloads.png)](https://packagist.org/packages/fresh/doctrine-enum-bundle) -[![Dependency Status](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/badge.svg)](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/5.3.x-dev) +* VersionEye [![Dependency Status](https://www.versioneye.com/user/projects/52ea10b1ec13755c2f000045/badge.svg)](https://www.versioneye.com/user/projects/52ea10b1ec13755c2f000045) [![Reference Status](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/reference_badge.svg)](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/references) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/0cff4816-374a-474e-a1d5-9d5db34562e3/big.png)](https://insight.sensiolabs.com/projects/0cff4816-374a-474e-a1d5-9d5db34562e3) [![knpbundles.com](http://knpbundles.com/fre5h/DoctrineEnumBundle/badge-short)](http://knpbundles.com/fre5h/DoctrineEnumBundle) +## Supported platforms + +* MySQL +* SQLite + ## Requirements -* Symfony 2.1 *and later* * PHP 5.4 *and later* +* Symfony 2.5 *and later* * Doctrine 2.2 *and later* ## Installation ### Install via Composer -Add the following lines to your `composer.json` file and then run `php composer.phar install` or `php composer.phar update`: - -```json -{ - "require": { - "fresh/doctrine-enum-bundle": "v2.5" - } -} -``` +```php composer.phar require fresh/doctrine-enum-bundle='v3.0'``` ### Register the bundle @@ -48,7 +41,7 @@ public function registerBundles() { $bundles = [ // Other bundles... - new Fresh\Bundle\DoctrineEnumBundle\FreshDoctrineEnumBundle(), + new Fresh\DoctrineEnumBundle\FreshDoctrineEnumBundle(), ]; } ``` @@ -61,7 +54,6 @@ Add the following lines for doctrine configuration in `config.yml` file: # Doctrine Configuration doctrine: dbal: - # Other options... mapping_types: enum: string ``` @@ -82,10 +74,10 @@ Create class for new ENUM type `BasketballPositionType`: ```php setPosition(BasketballPositionType::POINT_GUARD); But don't forget to define `BasketballPositionType` in the *use* section: ```php -use Application\Bundle\DefaultBundle\DBAL\Types\BasketballPositionType; +use Acme\AppBundle\DBAL\Types\BasketballPositionType; ``` `NULL` values are also supported by ENUM field. diff --git a/Resources/config/services.xml b/Resources/config/services.xml deleted file mode 100644 index 8607ee0..0000000 --- a/Resources/config/services.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - %doctrine.dbal.connection_factory.types% - - - - - - %doctrine.dbal.connection_factory.types% - - - diff --git a/Resources/config/services.yml b/Resources/config/services.yml new file mode 100644 index 0000000..1151196 --- /dev/null +++ b/Resources/config/services.yml @@ -0,0 +1,16 @@ +parameters: + twig.extension.readable_enum_value.class: Fresh\DoctrineEnumBundle\Twig\Extension\ReadableEnumValueExtension + enum_type_guesser.class: Fresh\DoctrineEnumBundle\Form\EnumTypeGuesser + +services: + twig.extension.readable_enum_value: + class: %twig.extension.readable_enum_value.class% + arguments: [%doctrine.dbal.connection_factory.types%] + tags: + - { name: twig.extension } + + enum_type_guesser: + class: %enum_type_guesser.class% + arguments: ["@doctrine", %doctrine.dbal.connection_factory.types%] + tags: + - { name: form.type_guesser } diff --git a/Tests/DBAL/Types/AbstractEnumTypeTest.php b/Tests/DBAL/Types/AbstractEnumTypeTest.php index 4fa6bfb..89d20ab 100644 --- a/Tests/DBAL/Types/AbstractEnumTypeTest.php +++ b/Tests/DBAL/Types/AbstractEnumTypeTest.php @@ -8,39 +8,43 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle\Tests\DBAL\Types; +namespace Fresh\DoctrineEnumBundle\Tests\DBAL\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Types\Type; +use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType; /** * AbstractEnumTypeTest * + * @author Artem Genvald * @author Ben Davies * - * @coversDefaultClass \Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType + * @coversDefaultClass \Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType */ class AbstractEnumTypeTest extends \PHPUnit_Framework_TestCase { /** - * @var \Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType + * @var AbstractEnumType */ private $type; /** - * Set up EnumType + * Set up before test suite */ - public function setUp() + public static function setUpBeforeClass() { - $this->type = $this->getMockBuilder('Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType') - ->disableOriginalConstructor() - ->setMethods(['getValues']) - ->getMockForAbstractClass(); + Type::addType('BasketballPositionType', '\Fresh\DoctrineEnumBundle\Fixtures\DBAL\Types\BasketballPositionType'); + } - $this->type->staticExpects($this->any()) - ->method('getValues') - ->will($this->returnValue(['M', 'F'])); + /** + * Set up environment + */ + public function setUp() + { + $this->type = Type::getType('BasketballPositionType'); } /** @@ -70,12 +74,12 @@ public function platformProvider() [ ['name' => 'sex'], new MySqlPlatform(), - "ENUM('M', 'F')" + "ENUM('PG', 'SG', 'SF', 'PF', 'C')" ], [ ['name' => 'sex'], new SqlitePlatform(), - "TEXT CHECK(sex IN ('M', 'F'))" + "TEXT CHECK(sex IN ('PG', 'SG', 'SF', 'PF', 'C'))" ] ]; } diff --git a/Tests/Twig/Extension/ReadableEnumValueExtensionTest.php b/Tests/Twig/Extension/ReadableEnumValueExtensionTest.php index fd53c2b..9c7c831 100644 --- a/Tests/Twig/Extension/ReadableEnumValueExtensionTest.php +++ b/Tests/Twig/Extension/ReadableEnumValueExtensionTest.php @@ -8,18 +8,18 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle\Tests\Twig\Extension; +namespace Fresh\DoctrineEnumBundle\Tests\Twig\Extension; -use Fresh\Bundle\DoctrineEnumBundle\Fixtures\DBAL\Types\BasketballPositionType; -use Fresh\Bundle\DoctrineEnumBundle\Fixtures\DBAL\Types\MapLocationType; -use Fresh\Bundle\DoctrineEnumBundle\Twig\Extension\ReadableEnumValueExtension; +use Fresh\DoctrineEnumBundle\Fixtures\DBAL\Types\BasketballPositionType; +use Fresh\DoctrineEnumBundle\Fixtures\DBAL\Types\MapLocationType; +use Fresh\DoctrineEnumBundle\Twig\Extension\ReadableEnumValueExtension; /** * ReadableEnumValueExtensionTest * * @author Artem Genvald * - * @coversDefaultClass \Fresh\Bundle\DoctrineEnumBundle\Twig\Extension\ReadableEnumValueExtension + * @coversDefaultClass \Fresh\DoctrineEnumBundle\Twig\Extension\ReadableEnumValueExtension */ class ReadableEnumValueExtensionTest extends \PHPUnit_Framework_TestCase { @@ -35,10 +35,10 @@ public function setUp() { $this->readableEnumValueExtension = new ReadableEnumValueExtension([ 'BasketballPositionType' => [ - 'class' => 'Fresh\Bundle\DoctrineEnumBundle\Fixtures\DBAL\Types\BasketballPositionType' + 'class' => 'Fresh\DoctrineEnumBundle\Fixtures\DBAL\Types\BasketballPositionType' ], 'MapLocationType' => [ - 'class' => 'Fresh\Bundle\DoctrineEnumBundle\Fixtures\DBAL\Types\MapLocationType' + 'class' => 'Fresh\DoctrineEnumBundle\Fixtures\DBAL\Types\MapLocationType' ] ]); } @@ -82,7 +82,7 @@ public function dataProviderForGetReadableEnumValueTest() * * @test * @covers ::getReadableEnumValue - * @expectedException \Fresh\Bundle\DoctrineEnumBundle\Exception\EnumTypeIsNotRegisteredException + * @expectedException \Fresh\DoctrineEnumBundle\Exception\EnumTypeIsNotRegisteredException */ public function enumTypeIsNotRegisteredException() { @@ -95,7 +95,7 @@ public function enumTypeIsNotRegisteredException() * * @test * @covers ::getReadableEnumValue - * @expectedException \Fresh\Bundle\DoctrineEnumBundle\Exception\ValueIsFoundInFewRegisteredEnumTypesException + * @expectedException \Fresh\DoctrineEnumBundle\Exception\ValueIsFoundInFewRegisteredEnumTypesException */ public function valueIsFoundInFewRegisteredEnumTypesException() { @@ -108,7 +108,7 @@ public function valueIsFoundInFewRegisteredEnumTypesException() * * @test * @covers ::getReadableEnumValue - * @expectedException \Fresh\Bundle\DoctrineEnumBundle\Exception\ValueIsNotFoundInAnyRegisteredEnumTypeException + * @expectedException \Fresh\DoctrineEnumBundle\Exception\ValueIsNotFoundInAnyRegisteredEnumTypeException */ public function valueIsNotFoundInAnyRegisteredEnumTypeException() { @@ -121,7 +121,7 @@ public function valueIsNotFoundInAnyRegisteredEnumTypeException() * * @test * @covers ::getReadableEnumValue - * @expectedException \Fresh\Bundle\DoctrineEnumBundle\Exception\NoRegisteredEnumTypesException + * @expectedException \Fresh\DoctrineEnumBundle\Exception\NoRegisteredEnumTypesException */ public function noRegisteredEnumTypesException() { diff --git a/Tests/Validator/EnumValidatorTest.php b/Tests/Validator/EnumValidatorTest.php index ecd5a71..f0d7f1a 100644 --- a/Tests/Validator/EnumValidatorTest.php +++ b/Tests/Validator/EnumValidatorTest.php @@ -8,38 +8,39 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle\Tests\Validator; +namespace Fresh\DoctrineEnumBundle\Tests\Validator; -use Fresh\Bundle\DoctrineEnumBundle\Fixtures\DBAL\Types\BasketballPositionType; -use Fresh\Bundle\DoctrineEnumBundle\Validator\Constraints\Enum; -use Fresh\Bundle\DoctrineEnumBundle\Validator\Constraints\EnumValidator; -use Symfony\Component\Validator\ExecutionContext; +use Fresh\DoctrineEnumBundle\Fixtures\DBAL\Types\BasketballPositionType; +use Fresh\DoctrineEnumBundle\Validator\Constraints\Enum; +use Fresh\DoctrineEnumBundle\Validator\Constraints\EnumValidator; +use Symfony\Component\Validator\Context\ExecutionContext; /** * EnumValidatorTest * * @author Artem Genvald * - * @coversDefaultClass \Fresh\Bundle\DoctrineEnumBundle\Validator\Constraints\EnumValidator + * @coversDefaultClass \Fresh\DoctrineEnumBundle\Validator\Constraints\EnumValidator */ class EnumValidatorTest extends \PHPUnit_Framework_TestCase { /** - * @var EnumValidator + * @var EnumValidator $enumValidator ENUM validator */ private $enumValidator; /** - * @var ExecutionContext|\PHPUnit_Framework_MockObject_MockObject + * @var ExecutionContext|\PHPUnit_Framework_MockObject_MockObject $context Context */ private $context; /** - * Set up EnumValidator + * Set up ENUM validator */ public function setUp() { $this->enumValidator = new EnumValidator(); + $this->context = $this->getMockBuilder('Symfony\Component\Validator\ExecutionContext') ->disableOriginalConstructor() ->getMock(); @@ -66,7 +67,7 @@ public function exceptionEntityNotSpecified() public function validBasketballPositionType() { $constraint = new Enum([ - 'entity' => 'Fresh\Bundle\DoctrineEnumBundle\Fixtures\DBAL\Types\BasketballPositionType' + 'entity' => 'Fresh\DoctrineEnumBundle\Fixtures\DBAL\Types\BasketballPositionType' ]); $this->context @@ -86,7 +87,7 @@ public function validBasketballPositionType() public function invalidBasketballPositionType() { $constraint = new Enum([ - 'entity' => 'Fresh\Bundle\DoctrineEnumBundle\Fixtures\DBAL\Types\BasketballPositionType' + 'entity' => 'Fresh\DoctrineEnumBundle\Fixtures\DBAL\Types\BasketballPositionType' ]); $this->context @@ -94,7 +95,7 @@ public function invalidBasketballPositionType() ->method('addViolation') ->with( $this->equalTo('The value you selected is not a valid choice.'), - $this->equalTo(['{{ value }}' => 'Pitcher']) + $this->equalTo(['{{ value }}' => '"Pitcher"']) ); $this->enumValidator->initialize($this->context); diff --git a/Twig/Extension/ReadableEnumValueExtension.php b/Twig/Extension/ReadableEnumValueExtension.php index e41c32d..4ebf79b 100644 --- a/Twig/Extension/ReadableEnumValueExtension.php +++ b/Twig/Extension/ReadableEnumValueExtension.php @@ -8,12 +8,12 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle\Twig\Extension; +namespace Fresh\DoctrineEnumBundle\Twig\Extension; -use Fresh\Bundle\DoctrineEnumBundle\Exception\EnumTypeIsNotRegisteredException; -use Fresh\Bundle\DoctrineEnumBundle\Exception\NoRegisteredEnumTypesException; -use Fresh\Bundle\DoctrineEnumBundle\Exception\ValueIsFoundInFewRegisteredEnumTypesException; -use Fresh\Bundle\DoctrineEnumBundle\Exception\ValueIsNotFoundInAnyRegisteredEnumTypeException; +use Fresh\DoctrineEnumBundle\Exception\EnumTypeIsNotRegisteredException; +use Fresh\DoctrineEnumBundle\Exception\NoRegisteredEnumTypesException; +use Fresh\DoctrineEnumBundle\Exception\ValueIsFoundInFewRegisteredEnumTypesException; +use Fresh\DoctrineEnumBundle\Exception\ValueIsNotFoundInAnyRegisteredEnumTypeException; /** * ReadableEnumValueExtension returns the readable variant of ENUM value @@ -25,7 +25,7 @@ class ReadableEnumValueExtension extends \Twig_Extension /** * Array of registered ENUM types * - * @var \Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType[] + * @var \Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType[] $registeredEnumTypes Registered ENUM types */ protected $registeredEnumTypes = []; @@ -37,7 +37,7 @@ class ReadableEnumValueExtension extends \Twig_Extension public function __construct(array $registeredTypes) { foreach ($registeredTypes as $type => $details) { - if (is_subclass_of($details['class'], '\Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType')) { + if (is_subclass_of($details['class'], '\Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType')) { $this->registeredEnumTypes[$type] = $details['class']; } } @@ -59,12 +59,12 @@ public function getFilters() * @param string $enumValue ENUM value * @param string|null $enumType ENUM type * - * @return string - * * @throws EnumTypeIsNotRegisteredException * @throws NoRegisteredEnumTypesException * @throws ValueIsFoundInFewRegisteredEnumTypesException * @throws ValueIsNotFoundInAnyRegisteredEnumTypeException + * + * @return string */ public function getReadableEnumValue($enumValue, $enumType = null) { @@ -75,7 +75,7 @@ public function getReadableEnumValue($enumValue, $enumType = null) throw new EnumTypeIsNotRegisteredException(sprintf('ENUM type "%s" is not registered', $enumType)); } - /** @var $enumTypeClass \Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType */ + /** @var $enumTypeClass \Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType */ $enumTypeClass = $this->registeredEnumTypes[$enumType]; return $enumTypeClass::getReadableValue($enumValue); @@ -115,7 +115,7 @@ public function getReadableEnumValue($enumValue, $enumType = null) /** * Get name of this extension * - * @return string + * @return string Name of extension */ public function getName() { diff --git a/Validator/Constraints/Enum.php b/Validator/Constraints/Enum.php index 798af3e..ffc2c22 100644 --- a/Validator/Constraints/Enum.php +++ b/Validator/Constraints/Enum.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle\Validator\Constraints; +namespace Fresh\DoctrineEnumBundle\Validator\Constraints; use Symfony\Component\Validator\Constraints\Choice; @@ -22,7 +22,7 @@ class Enum extends Choice { /** - * @var string Entity + * @var string $entity Entity */ public $entity; diff --git a/Validator/Constraints/EnumValidator.php b/Validator/Constraints/EnumValidator.php index bc2356a..68603ef 100644 --- a/Validator/Constraints/EnumValidator.php +++ b/Validator/Constraints/EnumValidator.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -namespace Fresh\Bundle\DoctrineEnumBundle\Validator\Constraints; +namespace Fresh\DoctrineEnumBundle\Validator\Constraints; use Symfony\Component\Validator\Constraints\ChoiceValidator; use Symfony\Component\Validator\Constraint; @@ -27,9 +27,9 @@ class EnumValidator extends ChoiceValidator * @param mixed $value The value that should be validated * @param Constraint $constraint The constraint for the validation * - * @return void - * * @throws ConstraintDefinitionException + * + * @return void */ public function validate($value, Constraint $constraint) { diff --git a/composer.json b/composer.json index 31064d7..c66cee1 100644 --- a/composer.json +++ b/composer.json @@ -2,31 +2,35 @@ "name": "fresh/doctrine-enum-bundle", "description": "Provides support of ENUM type for Doctrine2 in Symfony2 applications.", "keywords": ["bundle", "symfony", "doctrine", "entity", "enum", "type", "DBAL", "MySQL", "SQLite"], - "homepage": "https://github.com/fre5h/DoctrineEnumBundle", "type": "symfony-bundle", "license": "MIT", + "time": "2014-11-23", "authors": [ { "name": "Artem Genvald", "email": "genvaldartem@gmail.com", "role": "Creator" + }, + { + "name": "Community", + "homepage": "https://github.com/fre5h/DoctrineEnumBundle/graphs/contributors", + "role": "Developers" } ], - + "support": { + "email": "genvaldartem@gmail.com", + "issues": "https://github.com/fre5h/DoctrineEnumBundle/issues" + }, "require": { "php": ">=5.4.0", - "symfony/symfony": ">=2.1", - "doctrine/orm": ">=2.2" + "symfony/symfony": "~2.5", + "doctrine/orm": "~2.2" }, - "minimum-stability": "stable", - "autoload": { - "psr-0": { - "Fresh\\Bundle\\DoctrineEnumBundle": "" + "psr-4": { + "Fresh\\DoctrineEnumBundle\\": "" } - }, - - "target-dir": "Fresh/Bundle/DoctrineEnumBundle" + } } diff --git a/phpunit.xml b/phpunit.xml.dist similarity index 100% rename from phpunit.xml rename to phpunit.xml.dist