Skip to content

Commit 67cd890

Browse files
committed
Merge pull request #18 from fre5h/3.0
Refactoring
2 parents fac5960 + 4ae5005 commit 67cd890

22 files changed

+139
-150
lines changed

DBAL/Types/AbstractEnumType.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace Fresh\Bundle\DoctrineEnumBundle\DBAL\Types;
11+
namespace Fresh\DoctrineEnumBundle\DBAL\Types;
1212

1313
use Doctrine\DBAL\Platforms\AbstractPlatform;
1414
use Doctrine\DBAL\Platforms\SqlitePlatform;
@@ -30,7 +30,7 @@ abstract class AbstractEnumType extends Type
3030
protected $name = '';
3131

3232
/**
33-
* @var array Array of ENUM Values, where enum values are keys and their readable versions are values
33+
* @var array Array of ENUM Values, where ENUM values are keys and their readable versions are values
3434
* @static
3535
*/
3636
protected static $choices = [];
@@ -56,12 +56,15 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
5656
*/
5757
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
5858
{
59-
$values = implode(', ', array_map(
60-
function ($value) {
61-
return "'{$value}'";
62-
},
63-
$this->getValues()
64-
));
59+
$values = implode(
60+
', ',
61+
array_map(
62+
function ($value) {
63+
return "'{$value}'";
64+
},
65+
$this->getValues()
66+
)
67+
);
6568

6669
if ($platform instanceof SqlitePlatform) {
6770
return sprintf('TEXT CHECK(%s IN (%s))', $fieldDeclaration['name'], $values);

DependencyInjection/FreshDoctrineEnumExtension.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace Fresh\Bundle\DoctrineEnumBundle\DependencyInjection;
11+
namespace Fresh\DoctrineEnumBundle\DependencyInjection;
1212

1313
use Symfony\Component\Config\FileLocator;
1414
use Symfony\Component\DependencyInjection\ContainerBuilder;
15-
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
15+
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
1616
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
1717

1818
/**
@@ -30,17 +30,7 @@ class FreshDoctrineEnumExtension extends Extension
3030
*/
3131
public function load(array $configs, ContainerBuilder $container)
3232
{
33-
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
34-
$loader->load('services.xml');
35-
}
36-
37-
/**
38-
* Get alias
39-
*
40-
* @return string
41-
*/
42-
public function getAlias()
43-
{
44-
return 'fresh_doctrine_enum';
33+
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
34+
$loader->load('services.yml');
4535
}
4636
}

Exception/EnumTypeIsNotRegisteredException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace Fresh\Bundle\DoctrineEnumBundle\Exception;
11+
namespace Fresh\DoctrineEnumBundle\Exception;
1212

1313
/**
1414
* EnumTypeIsNotRegisteredException

Exception/EnumTypeIsRegisteredButClassDoesNotExistException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace Fresh\Bundle\DoctrineEnumBundle\Exception;
11+
namespace Fresh\DoctrineEnumBundle\Exception;
1212

1313
/**
1414
* EnumTypeIsRegisteredButClassDoesNotExistException

Exception/NoRegisteredEnumTypesException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace Fresh\Bundle\DoctrineEnumBundle\Exception;
11+
namespace Fresh\DoctrineEnumBundle\Exception;
1212

1313
/**
1414
* NoRegisteredEnumTypesException

Exception/ValueIsFoundInFewRegisteredEnumTypesException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace Fresh\Bundle\DoctrineEnumBundle\Exception;
11+
namespace Fresh\DoctrineEnumBundle\Exception;
1212

1313
/**
1414
* ValueIsFoundInFewRegisteredEnumTypesException

Exception/ValueIsNotFoundInAnyRegisteredEnumTypeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace Fresh\Bundle\DoctrineEnumBundle\Exception;
11+
namespace Fresh\DoctrineEnumBundle\Exception;
1212

1313
/**
1414
* ValueIsNotFoundInAnyRegisteredEnumTypeException

Fixtures/DBAL/Types/BasketballPositionType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace Fresh\Bundle\DoctrineEnumBundle\Fixtures\DBAL\Types;
11+
namespace Fresh\DoctrineEnumBundle\Fixtures\DBAL\Types;
1212

13-
use Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
13+
use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
1414

1515
/**
1616
* Basketball position type

Fixtures/DBAL/Types/MapLocationType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace Fresh\Bundle\DoctrineEnumBundle\Fixtures\DBAL\Types;
11+
namespace Fresh\DoctrineEnumBundle\Fixtures\DBAL\Types;
1212

13-
use Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
13+
use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
1414

1515
/**
1616
* Map location type

Form/EnumTypeGuesser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace Fresh\Bundle\DoctrineEnumBundle\Form;
11+
namespace Fresh\DoctrineEnumBundle\Form;
1212

1313
use Doctrine\Common\Persistence\ManagerRegistry;
14-
use Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
15-
use Fresh\Bundle\DoctrineEnumBundle\Exception\EnumTypeIsRegisteredButClassDoesNotExistException;
14+
use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
15+
use Fresh\DoctrineEnumBundle\Exception\EnumTypeIsRegisteredButClassDoesNotExistException;
1616
use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser;
1717
use Symfony\Component\Form\Guess\Guess;
1818
use Symfony\Component\Form\Guess\TypeGuess;
@@ -76,7 +76,7 @@ public function guessType($class, $property)
7676

7777
$enumTypeFullClassName = $this->registeredEnumTypes[$fieldType];
7878

79-
$abstractEnumTypeFullClassName = 'Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType';
79+
$abstractEnumTypeFullClassName = 'Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType';
8080

8181
if (get_parent_class($enumTypeFullClassName) !== $abstractEnumTypeFullClassName) {
8282
return null;

FreshDoctrineEnumBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace Fresh\Bundle\DoctrineEnumBundle;
11+
namespace Fresh\DoctrineEnumBundle;
1212

1313
use Symfony\Component\HttpKernel\Bundle\Bundle;
1414

README.md

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,36 @@
11
# DoctrineEnumBundle
22

3-
Provides support of **ENUM type** for Doctrine in Symfony applications
3+
Provides support of **ENUM type** for Doctrine in Symfony applications.
44

5-
[![License](https://poser.pugx.org/fresh/doctrine-enum-bundle/license.png)](https://packagist.org/packages/fresh/doctrine-enum-bundle)
6-
[![Build Status](https://secure.travis-ci.org/fre5h/DoctrineEnumBundle.png?branch=master)](https://travis-ci.org/fre5h/DoctrineEnumBundle)
7-
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/fre5h/DoctrineEnumBundle/badges/quality-score.png?s=be81f9b30a3996e7786cff5b4e0c0d972a64a37b)](https://scrutinizer-ci.com/g/fre5h/DoctrineEnumBundle/)
5+
* Scrutinizer [![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/fre5h/DoctrineEnumBundle/badges/quality-score.png?s=be81f9b30a3996e7786cff5b4e0c0d972a64a37b)](https://scrutinizer-ci.com/g/fre5h/DoctrineEnumBundle/)
6+
[![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)
7+
* Travis CI [![Build Status](https://secure.travis-ci.org/fre5h/DoctrineEnumBundle.png?branch=master)](https://travis-ci.org/fre5h/DoctrineEnumBundle)
8+
* Packagist.org [![License](https://poser.pugx.org/fresh/doctrine-enum-bundle/license.png)](https://packagist.org/packages/fresh/doctrine-enum-bundle)
89
[![Latest Stable Version](https://poser.pugx.org/fresh/doctrine-enum-bundle/v/stable.png)](https://packagist.org/packages/fresh/doctrine-enum-bundle)
910
[![Total Downloads](https://poser.pugx.org/fresh/doctrine-enum-bundle/downloads.png)](https://packagist.org/packages/fresh/doctrine-enum-bundle)
10-
[![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)
11+
* VersionEye [![Dependency Status](https://www.versioneye.com/user/projects/52ea10b1ec13755c2f000045/badge.svg)](https://www.versioneye.com/user/projects/52ea10b1ec13755c2f000045)
1112
[![Reference Status](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/reference_badge.svg)](https://www.versioneye.com/php/fresh:doctrine-enum-bundle/references)
1213

1314
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/0cff4816-374a-474e-a1d5-9d5db34562e3/big.png)](https://insight.sensiolabs.com/projects/0cff4816-374a-474e-a1d5-9d5db34562e3)
1415

1516
[![knpbundles.com](http://knpbundles.com/fre5h/DoctrineEnumBundle/badge-short)](http://knpbundles.com/fre5h/DoctrineEnumBundle)
1617

17-
## Supported platforms:
18+
## Supported platforms
1819

1920
* MySQL
2021
* SQLite
2122

2223
## Requirements
2324

24-
* Symfony 2.1 *and later*
2525
* PHP 5.4 *and later*
26+
* Symfony 2.5 *and later*
2627
* Doctrine 2.2 *and later*
2728

2829
## Installation
2930

3031
### Install via Composer
3132

32-
Add the following lines into your `composer.json` file:
33-
34-
```json
35-
{
36-
"require": {
37-
"fresh/doctrine-enum-bundle": "v2.5"
38-
}
39-
}
40-
```
41-
And then run `php composer.phar update`
33+
```php composer.phar require fresh/doctrine-enum-bundle='v3.0'```
4234

4335
### Register the bundle
4436

@@ -49,7 +41,7 @@ public function registerBundles()
4941
{
5042
$bundles = [
5143
// Other bundles...
52-
new Fresh\Bundle\DoctrineEnumBundle\FreshDoctrineEnumBundle(),
44+
new Fresh\DoctrineEnumBundle\FreshDoctrineEnumBundle(),
5345
];
5446
}
5547
```
@@ -62,7 +54,6 @@ Add the following lines for doctrine configuration in `config.yml` file:
6254
# Doctrine Configuration
6355
doctrine:
6456
dbal:
65-
# Other options...
6657
mapping_types:
6758
enum: string
6859
```
@@ -83,10 +74,10 @@ Create class for new ENUM type `BasketballPositionType`:
8374

8475
```php
8576
<?php
86-
namespace Application\Bundle\DefaultBundle\DBAL\Types;
77+
namespace Acme\AppBundle\DBAL\Types;
8778
8879
use Doctrine\DBAL\Platforms\AbstractPlatform;
89-
use Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
80+
use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
9081
9182
/**
9283
* Basketball position type
@@ -119,20 +110,19 @@ Register `BasketballPositionType` for Doctrine in config.yml:
119110
# Doctrine Configuration
120111
doctrine:
121112
dbal:
122-
# Other options...
123113
types:
124-
BasketballPositionType: Application\Bundle\DefaultBundle\DBAL\Types\BasketballPositionType
114+
BasketballPositionType: Acme\AppBundle\DBAL\Types\BasketballPositionType
125115
```
126116

127117
Create `Player` entity that has `position` field:
128118

129119
```php
130120
<?php
131-
namespace Application\Bundle\DefaultBundle\Entity;
121+
namespace Acme\AppBundle\Entity;
132122
133-
use Application\Bundle\DefaultBundle\DBAL\Types\BasketballPositionType;
123+
use Acme\AppBundle\DBAL\Types\BasketballPositionType;
134124
use Doctrine\ORM\Mapping as ORM;
135-
use Fresh\Bundle\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
125+
use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
136126
137127
/**
138128
* Player Entity
@@ -143,7 +133,7 @@ use Fresh\Bundle\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
143133
class Player
144134
{
145135
/**
146-
* @var int $id
136+
* @var int $id ID
147137
*
148138
* @ORM\Id
149139
* @ORM\Column(name="id", type="integer")
@@ -152,15 +142,15 @@ class Player
152142
protected $id;
153143
154144
/**
155-
* @var string $position
145+
* @var string $position Position
156146
*
157-
* @DoctrineAssert\Enum(entity="Application\Bundle\DefaultBundle\DBAL\Types\BasketballPositionType")
147+
* @DoctrineAssert\Enum(entity="Acme\AppBundle\DBAL\Types\BasketballPositionType")
158148
* @ORM\Column(name="position", type="BasketballPositionType", nullable=false)
159149
*/
160150
protected $position;
161151
162152
/**
163-
* Get id
153+
* Get ID
164154
*
165155
* @return int ID
166156
*/
@@ -200,7 +190,7 @@ $player->setPosition(BasketballPositionType::POINT_GUARD);
200190
But don't forget to define `BasketballPositionType` in the *use* section:
201191

202192
```php
203-
use Application\Bundle\DefaultBundle\DBAL\Types\BasketballPositionType;
193+
use Acme\AppBundle\DBAL\Types\BasketballPositionType;
204194
```
205195

206196
`NULL` values are also supported by ENUM field.

Resources/config/services.xml

Lines changed: 0 additions & 19 deletions
This file was deleted.

Resources/config/services.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
parameters:
2+
twig.extension.readable_enum_value.class: Fresh\DoctrineEnumBundle\Twig\Extension\ReadableEnumValueExtension
3+
enum_type_guesser.class: Fresh\DoctrineEnumBundle\Form\EnumTypeGuesser
4+
5+
services:
6+
twig.extension.readable_enum_value:
7+
class: %twig.extension.readable_enum_value.class%
8+
arguments: [%doctrine.dbal.connection_factory.types%]
9+
tags:
10+
- { name: twig.extension }
11+
12+
enum_type_guesser:
13+
class: %enum_type_guesser.class%
14+
arguments: ["@doctrine", %doctrine.dbal.connection_factory.types%]
15+
tags:
16+
- { name: form.type_guesser }

0 commit comments

Comments
 (0)