Skip to content

Commit

Permalink
Compiler pass checks for mappings (#112)
Browse files Browse the repository at this point in the history
* support Doctrine's MongoDB ODM

* fix CS

* fix travis adding mongodb service

* missing library for mongodb

* compiler pass checks
  • Loading branch information
juliangut authored and markitosgv committed Sep 18, 2018
1 parent 8843ae0 commit ab63298
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
23 changes: 20 additions & 3 deletions DependencyInjection/Compiler/DoctrineMappingsCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,33 @@
final class DoctrineMappingsCompilerPass implements CompilerPassInterface
{
/**
* Process Doctrine mappings based on gesdinet_jwt_refresh_token.refresh_token_entity config parameter.
* If this parameter contains user-defined entity, RefreshToken will be registered as a mapped superclass, not as an
* entity, to prevent Doctrine creating table for it and avoid conflicts with user-defined entity.
* Process Doctrine mappings based on gesdinet_jwt_refresh_token.manager_type and
* gesdinet_jwt_refresh_token.refresh_token_class config parameters.
* Depending on the value of manager_type Doctrine's ORM or ODM mappings will be used.
* If refresh_token_class parameter contains user-defined entity, RefreshToken will be registered as a mapped
* superclass, not as an entity, to prevent Doctrine creating table for it and avoid conflicts with user-defined
* entity.
*
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
$config = $container->getExtensionConfig('gesdinet_jwt_refresh_token')[0];

if (!class_exists('Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass')
&& (isset($config['manager_type']) && 'mongodb' === strtolower($config['manager_type']))
) {
// skip MongoDB ODM mappings
return;
}

if (!class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')
&& (!isset($config['manager_type']) || 'mongodb' !== strtolower($config['manager_type']))
) {
// skip ORM mappings
return;
}

$mappingPass = isset($config['manager_type']) && 'mongodb' === strtolower($config['manager_type'])
? $this->getODMCompilerPass($config)
: $this->getORMCompilerPass($config);
Expand Down
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,18 @@ Installation

### Step 1: Download the Bundle

Add [`gesdinet/jwt-refresh-token-bundle`](https://packagist.org/packages/gesdinet/jwt-refresh-token-bundle) to your `composer.json` file:
**It's important you manually require either Doctrine's ORM or MongoDB ODM as well, these packages are not required automatically now as you can choose between them. Failing to do so may trigger errors on installation**

```bash
$ composer require "gesdinet/jwt-refresh-token-bundle"
```

If you want to use Doctrine's ORM
With Doctrine's ORM

```bash
$ composer require "doctrine/orm" "doctrine/doctrine-bundle"
$ composer require "doctrine/orm" "doctrine/doctrine-bundle" "gesdinet/jwt-refresh-token-bundle"
```

If you want to use Doctrine's MongoDB ODM
With Doctrine's MongoDB ODM

```bash
$ composer require "doctrine/mongodb-odm-bundle"
$ composer require "doctrine/mongodb-odm-bundle" "gesdinet/jwt-refresh-token-bundle"
```

or edit composer.json:
Expand Down

0 comments on commit ab63298

Please sign in to comment.