-
-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split validation specific to the storage
- Loading branch information
1 parent
7dbd45b
commit dafad30
Showing
6 changed files
with
87 additions
and
14 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/DependencyInjection/Compiler/ValidationCompilerPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\UserBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ValidationCompilerPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
if (!$container->hasParameter('sonata.user.manager_type') | ||
|| !$container->hasDefinition('validator.builder')) { | ||
return; | ||
} | ||
|
||
$managerType = $container->getParameter('sonata.user.manager_type'); | ||
\assert(\is_string($managerType)); | ||
|
||
$container->getDefinition('validator.builder')->addMethodCall('addXmlMapping', [ | ||
sprintf( | ||
'%s/../../Resources/config/storage-validation/%s.xml', | ||
__DIR__, | ||
$managerType | ||
), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"> | ||
<class name="Sonata\UserBundle\Model\User"> | ||
<constraint name="Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique"> | ||
<option name="fields">email</option> | ||
<option name="errorPath">emailCanonical</option> | ||
<option name="groups"> | ||
<value>Registration</value> | ||
<value>Profile</value> | ||
</option> | ||
</constraint> | ||
<constraint name="Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique"> | ||
<option name="fields">username</option> | ||
<option name="errorPath">usernameCanonical</option> | ||
<option name="groups"> | ||
<value>Registration</value> | ||
<value>Profile</value> | ||
</option> | ||
</constraint> | ||
</class> | ||
</constraint-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"> | ||
<class name="Sonata\UserBundle\Model\User"> | ||
<constraint name="Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity"> | ||
<option name="fields">emailCanonical</option> | ||
<option name="errorPath">email</option> | ||
<option name="groups"> | ||
<value>Registration</value> | ||
<value>Profile</value> | ||
</option> | ||
</constraint> | ||
<constraint name="Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity"> | ||
<option name="fields">usernameCanonical</option> | ||
<option name="errorPath">username</option> | ||
<option name="groups"> | ||
<value>Registration</value> | ||
<value>Profile</value> | ||
</option> | ||
</constraint> | ||
</class> | ||
</constraint-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters