forked from KnpLabs/KnpUserBundle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a validator initializer for the canonical fields.
These fields need to be updated before validating their uniqueness.
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
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,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSUserBundle package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\UserBundle\Validator; | ||
|
||
use FOS\UserBundle\Model\UserInterface; | ||
use FOS\UserBundle\Model\UserManagerInterface; | ||
use Symfony\Component\Validator\ObjectInitializerInterface; | ||
|
||
/** | ||
* Automatically updates the canonical fields before validation. | ||
* | ||
* @author Christophe Coevoet <stof@notk.org> | ||
*/ | ||
class Initializer implements ObjectInitializerInterface | ||
{ | ||
private $userManager; | ||
|
||
public function __construct(UserManagerInterface $userManager) | ||
{ | ||
$this->userManager = $userManager; | ||
} | ||
|
||
public function initialize($object) | ||
{ | ||
if ($object instanceof UserInterface) { | ||
$this->userManager->updateCanonicalFields($object); | ||
} | ||
} | ||
} |