-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Changes from 6 commits
6290fd7
aa4b264
84f196b
d402948
973ad2c
9f5768d
e8b39a2
2fb70c3
9035936
1d4a579
46e4046
b7cd807
89be8e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
|
@@ -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')) { | ||
// TODO: provide a temporary implementation of the compiler pass in FOSUserBundle | ||
// so people can already use the Model class even with older symfony? | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
} |
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> |
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> |
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> |
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> |
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> |
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> |
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> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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