Skip to content

use the new doctrine compiler pass to map the model classes directly #1081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 25, 2013
Merged
1 change: 1 addition & 0 deletions DependencyInjection/FOSUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions Document/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

use FOS\UserBundle\Model\Group as BaseGroup;

/**
* @deprecated directly extend the model classes
*/
abstract class Group extends BaseGroup
{
}
3 changes: 3 additions & 0 deletions Document/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

use FOS\UserBundle\Model\User as AbstractUser;

/**
* @deprecated directly extend the model classes
*/
abstract class User extends AbstractUser
{
}
3 changes: 3 additions & 0 deletions Entity/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

use FOS\UserBundle\Model\Group as BaseGroup;

/**
* @deprecated directly extend the model classes
*/
class Group extends BaseGroup
{
}
3 changes: 3 additions & 0 deletions Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

use FOS\UserBundle\Model\User as AbstractUser;

/**
* @deprecated directly extend the model classes
*/
abstract class User extends AbstractUser
{
}
22 changes: 22 additions & 0 deletions FOSUserBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

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;

Expand All @@ -25,5 +27,25 @@ public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new ValidationPass());

if (! class_exists('Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterMappingsPass')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you move this logic into a private method if you want to return early ? this will void weird issues if someone else adds another piece of code in build later and does not notice this early return

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. i will add a fallback instead of return here, but still keeps the code more understandable

// TODO: provide a temporary implementation of the compiler pass in FOSUserBundle
// so people can already use the Model class even with older symfony?
return;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should i copy the compiler pass into FOSUserBundle so that we have a workaround until we can depend on the right symfony bridge and doctrine versions? otherwise things would not be backwards compatible as the mapping on Entity/Document/... is just a stub now and relies on the class in Model being properly mapped by doctrine.

}

$mappings = array(
realpath(__DIR__.'/Resources/config/doctrine/model') => 'FOS\UserBundle\Model',
);

if (class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')) {
$container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($mappings, 'fos_user.backend_type_orm'));
}

if (class_exists('Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass')) {
$container->addCompilerPass(DoctrineMongoDBMappingsPass::createXmlMappingDriver($mappings, 'fos_user.backend_type_mongodb'));
}

// TODO: couch
}
}
8 changes: 1 addition & 7 deletions Resources/config/doctrine/Group.couchdb.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping>
<mapped-superclass name="FOS\UserBundle\Document\Group" indexed="true">

<field name="name" fieldName="name" type="string" indexed="true" />
<field name="roles" fieldName="roles" type="mixed" />

</mapped-superclass>

<mapped-superclass name="FOS\UserBundle\CouchDocument\Group" indexed="true"/>
</doctrine-mapping>
15 changes: 1 addition & 14 deletions Resources/config/doctrine/Group.mongodb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,6 @@
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">

<mapped-superclass name="FOS\UserBundle\Document\Group" collection="fos_user_group">

<field name="name" fieldName="name" type="string" />

<field name="roles" fieldName="roles" type="collection" />

<indexes>
<index unique="true" dropDups="true">
<key name="name" order="asc" />
<option name="safe" value="true" />
</index>
</indexes>

</mapped-superclass>
<mapped-superclass name="FOS\UserBundle\Document\Group" collection="fos_user_group"/>

</doctrine-mongo-mapping>
8 changes: 1 addition & 7 deletions Resources/config/doctrine/Group.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<mapped-superclass name="FOS\UserBundle\Entity\Group">

<field name="name" column="name" type="string" length="255" unique="true" />

<field name="roles" column="roles" type="array" />

</mapped-superclass>
<mapped-superclass name="FOS\UserBundle\Entity\Group"/>

</doctrine-mapping>
19 changes: 1 addition & 18 deletions Resources/config/doctrine/User.couchdb.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping>

<mapped-superclass name="FOS\UserBundle\Document\User" indexed="true">

<field name="username" fieldName="username" type="string" indexed="true" />
<field name="usernameCanonical" fieldName="usernameCanonical" type="string" indexed="true" />
<field name="email" fieldName="email" type="string" indexed="true" />
<field name="emailCanonical" fieldName="emailCanonical" type="string" indexed="true" />
<field name="enabled" fieldName="enabled" type="mixed" />
<field name="salt" fieldName="salt" type="string" />
<field name="password" fieldName="password" type="string" />
<field name="lastLogin" fieldName="lastLogin" type="datetime" />
<field name="locked" fieldName="locked" type="mixed" />
<field name="expired" fieldName="expired" type="mixed" />
<field name="expiresAt" fieldName="expiresAt" type="datetime" />
<field name="confirmationToken" fieldName="confirmationToken" type="string" />
<field name="passwordRequestedAt" fieldName="passwordRequestedAt" type="datetime" />
<field name="roles" fieldName="roles" type="mixed" />

</mapped-superclass>
<mapped-superclass name="FOS\UserBundle\CouchDocument\User" indexed="true"/>

</doctrine-mapping>
43 changes: 1 addition & 42 deletions Resources/config/doctrine/User.mongodb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,6 @@
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">

<mapped-superclass name="FOS\UserBundle\Document\User" collection="fos_user_user">

<field name="username" fieldName="username" type="string" />

<field name="usernameCanonical" fieldName="usernameCanonical" type="string" />

<field name="email" fieldName="email" type="string" />

<field name="emailCanonical" fieldName="emailCanonical" type="string" />

<field name="enabled" fieldName="enabled" type="boolean" />

<field name="salt" fieldName="salt" type="string" />

<field name="password" fieldName="password" type="string" />

<field name="lastLogin" fieldName="lastLogin" type="date" />

<field name="locked" fieldName="locked" type="boolean" />

<field name="expired" fieldName="expired" type="boolean" />

<field name="expiresAt" fieldName="expiresAt" type="date" />

<field name="confirmationToken" fieldName="confirmationToken" type="string" />

<field name="passwordRequestedAt" fieldName="passwordRequestedAt" type="date" />

<field name="roles" fieldName="roles" type="collection" />

<indexes>
<index unique="true" dropDups="true">
<key name="usernameCanonical" order="asc" />
<option name="safe" value="true" />
</index>
<index unique="true" dropDups="true">
<key name="emailCanonical" order="asc" />
<option name="safe" value="true" />
</index>
</indexes>

</mapped-superclass>
<mapped-superclass name="FOS\UserBundle\Document\User" collection="fos_user_user"/>

</doctrine-mongo-mapping>
36 changes: 1 addition & 35 deletions Resources/config/doctrine/User.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,6 @@
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<mapped-superclass name="FOS\UserBundle\Entity\User">

<field name="username" column="username" type="string" length="255" />

<field name="usernameCanonical" column="username_canonical" type="string" length="255" unique="true" />

<field name="email" column="email" type="string" length="255" />

<field name="emailCanonical" column="email_canonical" type="string" length="255" unique="true" />

<field name="enabled" column="enabled" type="boolean" />

<field name="salt" column="salt" type="string" />

<field name="password" column="password" type="string" />

<field name="lastLogin" column="last_login" type="datetime" nullable="true" />

<field name="locked" column="locked" type="boolean" />

<field name="expired" column="expired" type="boolean" />

<field name="expiresAt" column="expires_at" type="datetime" nullable="true" />

<field name="confirmationToken" column="confirmation_token" type="string" nullable="true" />

<field name="passwordRequestedAt" column="password_requested_at" type="datetime" nullable="true" />

<field name="roles" column="roles" type="array" />

<field name="credentialsExpired" column="credentials_expired" type="boolean" />

<field name="credentialsExpireAt" column="credentials_expire_at" type="datetime" nullable="true" />

</mapped-superclass>
<mapped-superclass name="FOS\UserBundle\Entity\User" />

</doctrine-mapping>
10 changes: 10 additions & 0 deletions Resources/config/doctrine/model/Group.couchdb.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping>
<mapped-superclass name="FOS\UserBundle\Model\Group" indexed="true">

<field name="name" fieldName="name" type="string" indexed="true" />
<field name="roles" fieldName="roles" type="mixed" />

</mapped-superclass>

</doctrine-mapping>
22 changes: 22 additions & 0 deletions Resources/config/doctrine/model/Group.mongodb.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">

<mapped-superclass name="FOS\UserBundle\Model\Group" collection="fos_user_group">

<field name="name" fieldName="name" type="string" />

<field name="roles" fieldName="roles" type="collection" />

<indexes>
<index unique="true" dropDups="true">
<key name="name" order="asc" />
<option name="safe" value="true" />
</index>
</indexes>

</mapped-superclass>

</doctrine-mongo-mapping>
15 changes: 15 additions & 0 deletions Resources/config/doctrine/model/Group.orm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<mapped-superclass name="FOS\UserBundle\Model\Group">

<field name="name" column="name" type="string" length="255" unique="true" />

<field name="roles" column="roles" type="array" />

</mapped-superclass>

</doctrine-mapping>
23 changes: 23 additions & 0 deletions Resources/config/doctrine/model/User.couchdb.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping>

<mapped-superclass name="FOS\UserBundle\Model\User" indexed="true">

<field name="username" fieldName="username" type="string" indexed="true" />
<field name="usernameCanonical" fieldName="usernameCanonical" type="string" indexed="true" />
<field name="email" fieldName="email" type="string" indexed="true" />
<field name="emailCanonical" fieldName="emailCanonical" type="string" indexed="true" />
<field name="enabled" fieldName="enabled" type="mixed" />
<field name="salt" fieldName="salt" type="string" />
<field name="password" fieldName="password" type="string" />
<field name="lastLogin" fieldName="lastLogin" type="datetime" />
<field name="locked" fieldName="locked" type="mixed" />
<field name="expired" fieldName="expired" type="mixed" />
<field name="expiresAt" fieldName="expiresAt" type="datetime" />
<field name="confirmationToken" fieldName="confirmationToken" type="string" />
<field name="passwordRequestedAt" fieldName="passwordRequestedAt" type="datetime" />
<field name="roles" fieldName="roles" type="mixed" />

</mapped-superclass>

</doctrine-mapping>
50 changes: 50 additions & 0 deletions Resources/config/doctrine/model/User.mongodb.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">

<mapped-superclass name="FOS\UserBundle\Model\User" collection="fos_user_user">

<field name="username" fieldName="username" type="string" />

<field name="usernameCanonical" fieldName="usernameCanonical" type="string" />

<field name="email" fieldName="email" type="string" />

<field name="emailCanonical" fieldName="emailCanonical" type="string" />

<field name="enabled" fieldName="enabled" type="boolean" />

<field name="salt" fieldName="salt" type="string" />

<field name="password" fieldName="password" type="string" />

<field name="lastLogin" fieldName="lastLogin" type="date" />

<field name="locked" fieldName="locked" type="boolean" />

<field name="expired" fieldName="expired" type="boolean" />

<field name="expiresAt" fieldName="expiresAt" type="date" />

<field name="confirmationToken" fieldName="confirmationToken" type="string" />

<field name="passwordRequestedAt" fieldName="passwordRequestedAt" type="date" />

<field name="roles" fieldName="roles" type="collection" />

<indexes>
<index unique="true" dropDups="true">
<key name="usernameCanonical" order="asc" />
<option name="safe" value="true" />
</index>
<index unique="true" dropDups="true">
<key name="emailCanonical" order="asc" />
<option name="safe" value="true" />
</index>
</indexes>

</mapped-superclass>

</doctrine-mongo-mapping>
Loading