From 6290fd7b6278706327f21aae55844e7d23be0008 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 8 Apr 2013 14:10:59 +0200 Subject: [PATCH 01/13] use the new doctrine compiler pass to map the model classes directly --- DependencyInjection/FOSUserExtension.php | 1 + FOSUserBundle.php | 10 ++++++++++ .../config/doctrine/{ => model}/Group.couchdb.xml | 2 +- .../config/doctrine/{ => model}/Group.mongodb.xml | 2 +- Resources/config/doctrine/{ => model}/Group.orm.xml | 2 +- Resources/config/doctrine/{ => model}/User.couchdb.xml | 2 +- Resources/config/doctrine/{ => model}/User.mongodb.xml | 2 +- Resources/config/doctrine/{ => model}/User.orm.xml | 2 +- 8 files changed, 17 insertions(+), 6 deletions(-) rename Resources/config/doctrine/{ => model}/Group.couchdb.xml (76%) rename Resources/config/doctrine/{ => model}/Group.mongodb.xml (90%) rename Resources/config/doctrine/{ => model}/Group.orm.xml (90%) rename Resources/config/doctrine/{ => model}/User.couchdb.xml (94%) rename Resources/config/doctrine/{ => model}/User.mongodb.xml (95%) rename Resources/config/doctrine/{ => model}/User.orm.xml (96%) diff --git a/DependencyInjection/FOSUserExtension.php b/DependencyInjection/FOSUserExtension.php index fe4850af8a..cb089548fe 100644 --- a/DependencyInjection/FOSUserExtension.php +++ b/DependencyInjection/FOSUserExtension.php @@ -30,6 +30,7 @@ public function load(array $configs, ContainerBuilder $container) if ('custom' !== $config['db_driver']) { $loader->load(sprintf('%s.xml', $config['db_driver'])); + $container->setParameter($this->getAlias() . '.backend_type_' . $config['db_driver'], true); } foreach (array('validator', 'security', 'util', 'mailer', 'listeners') as $basename) { diff --git a/FOSUserBundle.php b/FOSUserBundle.php index 2de4fa2a12..86dc309e77 100644 --- a/FOSUserBundle.php +++ b/FOSUserBundle.php @@ -12,6 +12,7 @@ namespace FOS\UserBundle; use FOS\UserBundle\DependencyInjection\Compiler\ValidationPass; +use Doctrine\Bundle\DoctrineBundle\DependencyInjection\CompilerPass\RegisterMappingsPass; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -25,5 +26,14 @@ public function build(ContainerBuilder $container) { parent::build($container); $container->addCompilerPass(new ValidationPass()); + + if (class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\CompilerPass\RegisterMappingsPass')) { + $mappings = array( + realpath(__DIR__.'/Resources/config/doctrine/model') => 'FOS\UserBundle\Model', + ); + $container->addCompilerPass(new RegisterMappingsPass($mappings, 'xml', 'fos_user.backend_type_orm')); + } + + // TODO: couch, mongo } } diff --git a/Resources/config/doctrine/Group.couchdb.xml b/Resources/config/doctrine/model/Group.couchdb.xml similarity index 76% rename from Resources/config/doctrine/Group.couchdb.xml rename to Resources/config/doctrine/model/Group.couchdb.xml index 6f24c1bedc..539c382cb7 100644 --- a/Resources/config/doctrine/Group.couchdb.xml +++ b/Resources/config/doctrine/model/Group.couchdb.xml @@ -1,6 +1,6 @@ - + diff --git a/Resources/config/doctrine/Group.mongodb.xml b/Resources/config/doctrine/model/Group.mongodb.xml similarity index 90% rename from Resources/config/doctrine/Group.mongodb.xml rename to Resources/config/doctrine/model/Group.mongodb.xml index c153853602..6c62df82eb 100644 --- a/Resources/config/doctrine/Group.mongodb.xml +++ b/Resources/config/doctrine/model/Group.mongodb.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd"> - + diff --git a/Resources/config/doctrine/Group.orm.xml b/Resources/config/doctrine/model/Group.orm.xml similarity index 90% rename from Resources/config/doctrine/Group.orm.xml rename to Resources/config/doctrine/model/Group.orm.xml index 5c2499e983..e37a754e4e 100644 --- a/Resources/config/doctrine/Group.orm.xml +++ b/Resources/config/doctrine/model/Group.orm.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> - + diff --git a/Resources/config/doctrine/User.couchdb.xml b/Resources/config/doctrine/model/User.couchdb.xml similarity index 94% rename from Resources/config/doctrine/User.couchdb.xml rename to Resources/config/doctrine/model/User.couchdb.xml index 6d230ba7a8..43afbca7bd 100644 --- a/Resources/config/doctrine/User.couchdb.xml +++ b/Resources/config/doctrine/model/User.couchdb.xml @@ -1,7 +1,7 @@ - + diff --git a/Resources/config/doctrine/User.mongodb.xml b/Resources/config/doctrine/model/User.mongodb.xml similarity index 95% rename from Resources/config/doctrine/User.mongodb.xml rename to Resources/config/doctrine/model/User.mongodb.xml index 11933bfcdc..5495df5b28 100644 --- a/Resources/config/doctrine/User.mongodb.xml +++ b/Resources/config/doctrine/model/User.mongodb.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd"> - + diff --git a/Resources/config/doctrine/User.orm.xml b/Resources/config/doctrine/model/User.orm.xml similarity index 96% rename from Resources/config/doctrine/User.orm.xml rename to Resources/config/doctrine/model/User.orm.xml index aba6f92030..d029621198 100644 --- a/Resources/config/doctrine/User.orm.xml +++ b/Resources/config/doctrine/model/User.orm.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> - + From aa4b2642c6a8dec87731ad4655d5e58d2e1f5bc9 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 8 Apr 2013 14:15:45 +0200 Subject: [PATCH 02/13] deprecate persistence specific classes --- Document/Group.php | 3 +++ Document/User.php | 3 +++ Entity/Group.php | 3 +++ Entity/User.php | 3 +++ 4 files changed, 12 insertions(+) diff --git a/Document/Group.php b/Document/Group.php index 9ce2d80e51..6e75bf9857 100644 --- a/Document/Group.php +++ b/Document/Group.php @@ -13,6 +13,9 @@ use FOS\UserBundle\Model\Group as BaseGroup; +/** + * @deprecated directly extend the model classes + */ abstract class Group extends BaseGroup { } diff --git a/Document/User.php b/Document/User.php index fac430dad8..44a7cabeb1 100644 --- a/Document/User.php +++ b/Document/User.php @@ -13,6 +13,9 @@ use FOS\UserBundle\Model\User as AbstractUser; +/** + * @deprecated directly extend the model classes + */ abstract class User extends AbstractUser { } diff --git a/Entity/Group.php b/Entity/Group.php index e7a7d240c4..a206923b37 100644 --- a/Entity/Group.php +++ b/Entity/Group.php @@ -13,6 +13,9 @@ use FOS\UserBundle\Model\Group as BaseGroup; +/** + * @deprecated directly extend the model classes + */ class Group extends BaseGroup { } diff --git a/Entity/User.php b/Entity/User.php index 493a63e2db..9078f0bc7c 100644 --- a/Entity/User.php +++ b/Entity/User.php @@ -13,6 +13,9 @@ use FOS\UserBundle\Model\User as AbstractUser; +/** + * @deprecated directly extend the model classes + */ abstract class User extends AbstractUser { } From 84f196b0bfa8068936ea2de6565ba7615dad3ee6 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 15 Apr 2013 20:38:39 +0200 Subject: [PATCH 03/13] adjust to factory method --- FOSUserBundle.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FOSUserBundle.php b/FOSUserBundle.php index 86dc309e77..46bdff6634 100644 --- a/FOSUserBundle.php +++ b/FOSUserBundle.php @@ -12,7 +12,7 @@ namespace FOS\UserBundle; use FOS\UserBundle\DependencyInjection\Compiler\ValidationPass; -use Doctrine\Bundle\DoctrineBundle\DependencyInjection\CompilerPass\RegisterMappingsPass; +use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -27,11 +27,11 @@ public function build(ContainerBuilder $container) parent::build($container); $container->addCompilerPass(new ValidationPass()); - if (class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\CompilerPass\RegisterMappingsPass')) { + if (class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')) { $mappings = array( realpath(__DIR__.'/Resources/config/doctrine/model') => 'FOS\UserBundle\Model', ); - $container->addCompilerPass(new RegisterMappingsPass($mappings, 'xml', 'fos_user.backend_type_orm')); + $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($mappings, 'fos_user.backend_type_orm')); } // TODO: couch, mongo From d40294893ab233996a1f80e75c5954f7240cc97e Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 15 Apr 2013 20:41:46 +0200 Subject: [PATCH 04/13] re-adding empty mapping files to keep BC compatibility --- Resources/config/doctrine/Group.couchdb.xml | 4 ++++ Resources/config/doctrine/Group.mongodb.xml | 9 +++++++++ Resources/config/doctrine/Group.orm.xml | 9 +++++++++ Resources/config/doctrine/User.couchdb.xml | 6 ++++++ Resources/config/doctrine/User.mongodb.xml | 9 +++++++++ Resources/config/doctrine/User.orm.xml | 9 +++++++++ 6 files changed, 46 insertions(+) create mode 100644 Resources/config/doctrine/Group.couchdb.xml create mode 100644 Resources/config/doctrine/Group.mongodb.xml create mode 100644 Resources/config/doctrine/Group.orm.xml create mode 100644 Resources/config/doctrine/User.couchdb.xml create mode 100644 Resources/config/doctrine/User.mongodb.xml create mode 100644 Resources/config/doctrine/User.orm.xml diff --git a/Resources/config/doctrine/Group.couchdb.xml b/Resources/config/doctrine/Group.couchdb.xml new file mode 100644 index 0000000000..875cd30022 --- /dev/null +++ b/Resources/config/doctrine/Group.couchdb.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Resources/config/doctrine/Group.mongodb.xml b/Resources/config/doctrine/Group.mongodb.xml new file mode 100644 index 0000000000..e5802fd563 --- /dev/null +++ b/Resources/config/doctrine/Group.mongodb.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/Resources/config/doctrine/Group.orm.xml b/Resources/config/doctrine/Group.orm.xml new file mode 100644 index 0000000000..261af5211b --- /dev/null +++ b/Resources/config/doctrine/Group.orm.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/Resources/config/doctrine/User.couchdb.xml b/Resources/config/doctrine/User.couchdb.xml new file mode 100644 index 0000000000..489fd6d10a --- /dev/null +++ b/Resources/config/doctrine/User.couchdb.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/Resources/config/doctrine/User.mongodb.xml b/Resources/config/doctrine/User.mongodb.xml new file mode 100644 index 0000000000..53dccc8022 --- /dev/null +++ b/Resources/config/doctrine/User.mongodb.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/Resources/config/doctrine/User.orm.xml b/Resources/config/doctrine/User.orm.xml new file mode 100644 index 0000000000..67182347eb --- /dev/null +++ b/Resources/config/doctrine/User.orm.xml @@ -0,0 +1,9 @@ + + + + + + From 973ad2cf981119d3501b1b965611a6a4befbbca0 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 17 Apr 2013 23:13:51 +0200 Subject: [PATCH 05/13] add support for mongo --- FOSUserBundle.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/FOSUserBundle.php b/FOSUserBundle.php index 46bdff6634..3b4856fc72 100644 --- a/FOSUserBundle.php +++ b/FOSUserBundle.php @@ -11,6 +11,7 @@ namespace FOS\UserBundle; +use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass; use FOS\UserBundle\DependencyInjection\Compiler\ValidationPass; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -27,13 +28,18 @@ public function build(ContainerBuilder $container) parent::build($container); $container->addCompilerPass(new ValidationPass()); + $mappings = array( + realpath(__DIR__.'/Resources/config/doctrine/model') => 'FOS\UserBundle\Model', + ); + if (class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')) { - $mappings = array( - realpath(__DIR__.'/Resources/config/doctrine/model') => 'FOS\UserBundle\Model', - ); $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($mappings, 'fos_user.backend_type_orm')); } - // TODO: couch, mongo + if (class_exists('Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass')) { + $container->addCompilerPass(DoctrineMongoDBMappingsPass::createXmlMappingDriver($mappings, 'fos_user.backend_type_mongodb')); + } + + // TODO: couch } } From 9f5768d44c8da4ff629faa4055a2dc7453f0add6 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 17 Apr 2013 23:14:40 +0200 Subject: [PATCH 06/13] do not have a fatal error if doctrine bridge is too old --- FOSUserBundle.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/FOSUserBundle.php b/FOSUserBundle.php index 3b4856fc72..f64d351a10 100644 --- a/FOSUserBundle.php +++ b/FOSUserBundle.php @@ -28,6 +28,12 @@ public function build(ContainerBuilder $container) parent::build($container); $container->addCompilerPass(new ValidationPass()); + if (! class_exists('Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterMappingsPass')) { + // TODO: provide a temporary implementation of the compiler pass in FOSUserBundle + // so people can already use the Model class even with older symfony? + return; + } + $mappings = array( realpath(__DIR__.'/Resources/config/doctrine/model') => 'FOS\UserBundle\Model', ); From e8b39a26de9eee3ce072d0bd1a0ca2f440a0a0cd Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 21 Apr 2013 10:52:18 +0200 Subject: [PATCH 07/13] adjust to https://github.com/symfony/symfony/pull/7755 --- FOSUserBundle.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/FOSUserBundle.php b/FOSUserBundle.php index f64d351a10..2433b6dd16 100644 --- a/FOSUserBundle.php +++ b/FOSUserBundle.php @@ -11,11 +11,11 @@ namespace FOS\UserBundle; -use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass; -use FOS\UserBundle\DependencyInjection\Compiler\ValidationPass; -use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; +use FOS\UserBundle\DependencyInjection\Compiler\ValidationPass; +use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass; +use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass; /** * @author Matthieu Bontemps @@ -39,11 +39,11 @@ public function build(ContainerBuilder $container) ); if (class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')) { - $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($mappings, 'fos_user.backend_type_orm')); + $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($mappings, array('fos_user.model_manager_name'), 'fos_user.backend_type_orm')); } if (class_exists('Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass')) { - $container->addCompilerPass(DoctrineMongoDBMappingsPass::createXmlMappingDriver($mappings, 'fos_user.backend_type_mongodb')); + $container->addCompilerPass(DoctrineMongoDBMappingsPass::createXmlMappingDriver($mappings, array('fos_user.model_manager_name'), 'fos_user.backend_type_mongodb')); } // TODO: couch From 2fb70c32b51fe376a54302add21319026c386cfd Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 25 Apr 2013 08:44:50 +0200 Subject: [PATCH 08/13] add legacy symfony support --- .../Compiler/RegisterMappingsPass.php | 86 +++++++++++++++++++ FOSUserBundle.php | 27 ++++-- 2 files changed, 105 insertions(+), 8 deletions(-) create mode 100644 DependencyInjection/Compiler/RegisterMappingsPass.php diff --git a/DependencyInjection/Compiler/RegisterMappingsPass.php b/DependencyInjection/Compiler/RegisterMappingsPass.php new file mode 100644 index 0000000000..652f6a2e1e --- /dev/null +++ b/DependencyInjection/Compiler/RegisterMappingsPass.php @@ -0,0 +1,86 @@ + + */ +class RegisterMappingsPass implements CompilerPassInterface +{ + private $driver; + private $driverPattern; + private $namespaces; + private $enabledParameter; + private $fallbackManagerParameter; + + public function __construct($driver, $driverPattern, $namespaces, $enabledParameter, $fallbackManagerParameter) + { + $this->driver = $driver; + $this->driverPattern = $driverPattern; + $this->namespaces = $namespaces; + $this->enabledParameter = $enabledParameter; + $this->fallbackManagerParameter = $fallbackManagerParameter; + } + + /** + * Register mappings with the metadata drivers. + * + * @param ContainerBuilder $container + */ + public function process(ContainerBuilder $container) + { + if (!$container->hasParameter($this->enabledParameter)) { + return; + } + + $chainDriverDefService = $this->getChainDriverServiceName($container); + $chainDriverDef = $container->getDefinition($chainDriverDefService); + foreach ($this->namespaces as $namespace) { + $chainDriverDef->addMethodCall('addDriver', array($this->driver, $namespace)); + } + } + + protected function getChainDriverServiceName(ContainerBuilder $container) + { + foreach (array('fos_user.model_manager_name', $this->fallbackManagerParameter) as $param) { + if ($container->hasParameter($param)) { + $name = $container->getParameter($param); + if ($name) { + return sprintf($this->driverPattern, $name); + } + } + } + + throw new ParameterNotFoundException('None of the managerParameters resulted in a valid name'); + } + + public static function createOrmMappingDriver(array $mappings) + { + $arguments = array($mappings, '.orm.xml'); + $locator = new Definition('Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator', $arguments); + $driver = new Definition('Doctrine\ORM\Mapping\Driver\XmlDriver', array($locator)); + + return new RegisterMappingsPass($driver, 'doctrine.orm.%s_metadata_driver', $mappings, 'fos_user.backend_type_orm', 'doctrine.default_entity_manager'); + } + + public static function createMongoDBMappingDriver($mappings) + { + $arguments = array($mappings, '.mongodb.xml'); + $locator = new Definition('Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator', $arguments); + $driver = new Definition('Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver', array($locator)); + + return new RegisterMappingsPass($driver, 'doctrine_mongodb.odm.%s_metadata_driver', $mappings, 'fos_user.backend_type_mongodb', 'doctrine_mongodb.odm.default_document_manager'); + } +} diff --git a/FOSUserBundle.php b/FOSUserBundle.php index 2433b6dd16..c80e6feb6d 100644 --- a/FOSUserBundle.php +++ b/FOSUserBundle.php @@ -11,6 +11,7 @@ namespace FOS\UserBundle; +use FOS\UserBundle\DependencyInjection\Compiler\RegisterMappingsPass; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; use FOS\UserBundle\DependencyInjection\Compiler\ValidationPass; @@ -23,27 +24,37 @@ */ class FOSUserBundle extends Bundle { + public function build(ContainerBuilder $container) { parent::build($container); $container->addCompilerPass(new ValidationPass()); - if (! class_exists('Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterMappingsPass')) { - // TODO: provide a temporary implementation of the compiler pass in FOSUserBundle - // so people can already use the Model class even with older symfony? - return; - } + $this->addRegisterMappingsPass($container); + } + + /** + * @param ContainerBuilder $container + */ + private function addRegisterMappingsPass(ContainerBuilder $container) + { + // the base class is only available since symfony 2.3 + $symfonyVersion = class_exists('Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterMappingsPass'); $mappings = array( - realpath(__DIR__.'/Resources/config/doctrine/model') => 'FOS\UserBundle\Model', + realpath(__DIR__ . '/Resources/config/doctrine/model') => 'FOS\UserBundle\Model', ); - if (class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')) { + if ($symfonyVersion && class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')) { $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($mappings, array('fos_user.model_manager_name'), 'fos_user.backend_type_orm')); + } else { + $container->addCompilerPass(RegisterMappingsPass::createOrmMappingDriver($mappings)); } - if (class_exists('Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass')) { + if ($symfonyVersion && class_exists('Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass')) { $container->addCompilerPass(DoctrineMongoDBMappingsPass::createXmlMappingDriver($mappings, array('fos_user.model_manager_name'), 'fos_user.backend_type_mongodb')); + } else { + $container->addCompilerPass(RegisterMappingsPass::createMongoDBMappingDriver($mappings)); } // TODO: couch From 9035936abe0d31f8c0a02b23251f24f27d6c2e98 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 7 May 2013 11:56:38 +0200 Subject: [PATCH 09/13] add support for couchdb --- DependencyInjection/Compiler/RegisterMappingsPass.php | 9 +++++++++ FOSUserBundle.php | 9 +++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/Compiler/RegisterMappingsPass.php b/DependencyInjection/Compiler/RegisterMappingsPass.php index 652f6a2e1e..b18bf8ca37 100644 --- a/DependencyInjection/Compiler/RegisterMappingsPass.php +++ b/DependencyInjection/Compiler/RegisterMappingsPass.php @@ -83,4 +83,13 @@ public static function createMongoDBMappingDriver($mappings) return new RegisterMappingsPass($driver, 'doctrine_mongodb.odm.%s_metadata_driver', $mappings, 'fos_user.backend_type_mongodb', 'doctrine_mongodb.odm.default_document_manager'); } + + public static function createCouchDBMappingDriver($mappings) + { + $arguments = array($mappings, '.couchdb.xml'); + $locator = new Definition('Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator', $arguments); + $driver = new Definition('Doctrine\ODM\CouchDB\Mapping\Driver\XmlDriver', array($locator)); + + return new RegisterMappingsPass($driver, 'doctrine_couchdb.odm.%s_metadata_driver', $mappings, 'fos_user.backend_type_couchdb', 'doctrine_couchdb.default_document_manager'); + } } diff --git a/FOSUserBundle.php b/FOSUserBundle.php index c80e6feb6d..295fdc2083 100644 --- a/FOSUserBundle.php +++ b/FOSUserBundle.php @@ -11,12 +11,13 @@ namespace FOS\UserBundle; -use FOS\UserBundle\DependencyInjection\Compiler\RegisterMappingsPass; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; use FOS\UserBundle\DependencyInjection\Compiler\ValidationPass; +use FOS\UserBundle\DependencyInjection\Compiler\RegisterMappingsPass; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass; use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass; +use Doctrine\Bundle\CouchDBBundle\DependencyInjection\Compiler\DoctrineCouchDBMappingsPass; /** * @author Matthieu Bontemps @@ -57,6 +58,10 @@ private function addRegisterMappingsPass(ContainerBuilder $container) $container->addCompilerPass(RegisterMappingsPass::createMongoDBMappingDriver($mappings)); } - // TODO: couch + if ($symfonyVersion && class_exists('Doctrine\Bundle\CouchDBBundle\DependencyInjection\Compiler\DoctrineCouchDBMappingsPass')) { + $container->addCompilerPass(DoctrineCouchDBMappingsPass::createXmlMappingDriver($mappings, array('fos_user.model_manager_name'), 'fos_user.backend_type_couchdb')); + } else { + $container->addCompilerPass(RegisterMappingsPass::createCouchDBMappingDriver($mappings)); + } } } From 1d4a5792d669cb60a6ae744dd64be126d51b6586 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 7 May 2013 11:56:51 +0200 Subject: [PATCH 10/13] updated documentation --- Resources/doc/index.md | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 3bc9e21443..f10996214e 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -87,7 +87,8 @@ properties or methods you find useful. This is *your* `User` class. The bundle provides base classes which are already mapped for most fields to make it easier to create your entity. Here is how you use it: -1. Extend the base `User` class (the class to use depends of your storage) +1. Extend the base `User` class (from the ``Model`` folder if you are using + any of the doctrine variants, or ``Propel`` for propel) 2. Map the `id` field. It must be protected as it is inherited from the parent class. **Warning:** @@ -95,14 +96,14 @@ to make it easier to create your entity. Here is how you use it: > When you extend from the mapped superclass provided by the bundle, don't > redefine the mapping for the other fields as it is provided by the bundle. -In the following sections, you'll see examples of how your `User` class should -look, depending on how you're storing your users (Doctrine ORM, MongoDB ODM, -or CouchDB ODM). - Your `User` class can live inside any bundle in your application. For example, if you work at "Acme" company, then you might create a bundle called `AcmeUserBundle` and place your `User` class in it. +In the following sections, you'll see examples of how your `User` class should +look, depending on how you're storing your users (Doctrine ORM, MongoDB ODM, +or CouchDB ODM). + **Note:** > The doc uses a bundle named `AcmeUserBundle`. If you want to use the same @@ -127,7 +128,7 @@ start: namespace Acme\UserBundle\Entity; -use FOS\UserBundle\Entity\User as BaseUser; +use FOS\UserBundle\Model\User as BaseUser; use Doctrine\ORM\Mapping as ORM; /** @@ -167,7 +168,7 @@ this to start: namespace Acme\UserBundle\Document; -use FOS\UserBundle\Document\User as BaseUser; +use FOS\UserBundle\Model\User as BaseUser; use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; /** @@ -200,7 +201,7 @@ this to start: namespace Acme\UserBundle\Document; -use FOS\UserBundle\Document\User as BaseUser; +use FOS\UserBundle\Model\User as BaseUser; use Doctrine\ODM\CouchDB\Mapping as CouchDB; /** @@ -286,7 +287,7 @@ provider for the firewall to use as part of the authentication process. > Although we have used the form login mechanism in this example, the FOSUserBundle > user provider service is compatible with many other authentication methods as well. -> Please read the Symfony2 Security component documention for more information on the +> Please read the Symfony2 Security component documentation for more information on the > other types of authentication methods. The `access_control` section is where you specify the credentials necessary for @@ -344,12 +345,12 @@ Only three configuration values are required to use the bundle: * The firewall name which you configured in Step 5. * The fully qualified class name (FQCN) of the `User` class which you created in Step 4. -**Warning:** +**Note:** -> When using one of the Doctrine implementation, you need either to use the -> `auto_mapping` option of the corresponding bundle (done by default for -> DoctrineBundle in the standard distribution) or to activate the mapping -> for FOSUserBundle otherwise the base mapping will be ignored. +> FOSUserBundle uses a compiler pass to register mappings for the base +> User and Group model classes with the object manager that you configured +> it to use. (Unless specified explicitly, this is the default manager +> of your doctrine configuration.) ### Step 6: Import FOSUserBundle routing files From 46e40463aea09bf82255e70b8ad89c4881818e30 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 7 May 2013 12:00:21 +0200 Subject: [PATCH 11/13] added upgrade instructions --- Upgrade.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Upgrade.md b/Upgrade.md index a7f17b05ec..081987b48d 100644 --- a/Upgrade.md +++ b/Upgrade.md @@ -4,6 +4,18 @@ Upgrade instruction This document describes the changes needed when upgrading because of a BC break. For the full list of changes, please look at the Changelog file. +## 1.3.1 to 1.3.2 + +### User and Group class + +This bundle now registers mappings for the classes in Model directly, instead +of having empty extending classes. The Entity/User and Document/User and Group +classes are deprecated, you should update your User and Group classes to extend +the classes found in Model directly. +The old classes will stay around for a while and continue to work, but will be +dropped for version 2.0. + + ## 1.2 to 1.3 ### Forms From b7cd807b6f554d19ff74d575827a28beb20712ee Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 7 May 2013 12:05:54 +0200 Subject: [PATCH 12/13] put #1113 into this PR --- Resources/doc/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Resources/doc/index.md b/Resources/doc/index.md index f10996214e..a4c5add41e 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -192,17 +192,17 @@ class User extends BaseUser **c) CouchDB User class** If you're persisting your users via the Doctrine CouchDB ODM, then your `User` -class should live in the `Document` namespace of your bundle and look like +class should live in the `CouchDocument` namespace of your bundle and look like this to start: ``` php Date: Fri, 10 May 2013 16:04:13 +0200 Subject: [PATCH 13/13] add deprecated errors to constructors, fix Upgrade.md --- Document/Group.php | 8 +++++++- Document/User.php | 8 +++++++- Entity/Group.php | 8 +++++++- Entity/User.php | 8 +++++++- FOSUserBundle.php | 1 - Upgrade.md | 15 +++++++-------- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/Document/Group.php b/Document/Group.php index 6e75bf9857..cb77931585 100644 --- a/Document/Group.php +++ b/Document/Group.php @@ -14,8 +14,14 @@ use FOS\UserBundle\Model\Group as BaseGroup; /** - * @deprecated directly extend the model classes + * @deprecated directly extend the classes in the Model namespace */ abstract class Group extends BaseGroup { + public function __construct($name, $roles = array()) + { + // you should extend the class in the Model namespace directly + trigger_error(E_USER_DEPRECATED); + parent::__construct($name, $roles); + } } diff --git a/Document/User.php b/Document/User.php index 44a7cabeb1..460fe3a1da 100644 --- a/Document/User.php +++ b/Document/User.php @@ -14,8 +14,14 @@ use FOS\UserBundle\Model\User as AbstractUser; /** - * @deprecated directly extend the model classes + * @deprecated directly extend the classes in the Model namespace */ abstract class User extends AbstractUser { + public function __construct() + { + // you should extend the class in the Model namespace directly + trigger_error(E_USER_DEPRECATED); + parent::__construct(); + } } diff --git a/Entity/Group.php b/Entity/Group.php index a206923b37..755c138ba7 100644 --- a/Entity/Group.php +++ b/Entity/Group.php @@ -14,8 +14,14 @@ use FOS\UserBundle\Model\Group as BaseGroup; /** - * @deprecated directly extend the model classes + * @deprecated directly extend the classes in the Model namespace */ class Group extends BaseGroup { + public function __construct($name, $roles = array()) + { + // you should extend the class in the Model namespace directly + trigger_error(E_USER_DEPRECATED); + parent::__construct($name, $roles); + } } diff --git a/Entity/User.php b/Entity/User.php index 9078f0bc7c..4dc5e43168 100644 --- a/Entity/User.php +++ b/Entity/User.php @@ -14,8 +14,14 @@ use FOS\UserBundle\Model\User as AbstractUser; /** - * @deprecated directly extend the model classes + * @deprecated directly extend the classes in the Model namespace */ abstract class User extends AbstractUser { + public function __construct() + { + // you should extend the class in the Model namespace directly + trigger_error(E_USER_DEPRECATED); + parent::__construct(); + } } diff --git a/FOSUserBundle.php b/FOSUserBundle.php index 295fdc2083..044dc672ab 100644 --- a/FOSUserBundle.php +++ b/FOSUserBundle.php @@ -25,7 +25,6 @@ */ class FOSUserBundle extends Bundle { - public function build(ContainerBuilder $container) { parent::build($container); diff --git a/Upgrade.md b/Upgrade.md index 081987b48d..c17f0520f5 100644 --- a/Upgrade.md +++ b/Upgrade.md @@ -4,17 +4,16 @@ Upgrade instruction This document describes the changes needed when upgrading because of a BC break. For the full list of changes, please look at the Changelog file. -## 1.3.1 to 1.3.2 +## 1.3 to 2.0 ### User and Group class -This bundle now registers mappings for the classes in Model directly, instead -of having empty extending classes. The Entity/User and Document/User and Group -classes are deprecated, you should update your User and Group classes to extend -the classes found in Model directly. -The old classes will stay around for a while and continue to work, but will be -dropped for version 2.0. - +This bundle now (registers mappings)[http://symfony.com/doc/master/cookbook/doctrine/mapping_model_classes.html] +for the classes in the Model namespace directly, instead +of having empty extending classes. The User and Group classes in the Entity and +Document namespaces are deprecated, you should update your User and Group +classes to extend the classes found in `Model`. +The old classes will stay until 2.0 is released stable, but throw deprecated warnings. ## 1.2 to 1.3