diff --git a/DependencyInjection/Compiler/DoctrineMappingsCompilerPass.php b/DependencyInjection/Compiler/DoctrineMappingsCompilerPass.php index 324b67ab..8da58165 100644 --- a/DependencyInjection/Compiler/DoctrineMappingsCompilerPass.php +++ b/DependencyInjection/Compiler/DoctrineMappingsCompilerPass.php @@ -17,9 +17,12 @@ 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 */ @@ -27,6 +30,20 @@ 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); diff --git a/README.md b/README.md index 7632000a..5741d561 100644 --- a/README.md +++ b/README.md @@ -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: