ValidationPass.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /*
  3. * This file is part of the FOSUserBundle package.
  4. *
  5. * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace FOS\UserBundle\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\ContainerBuilder;
  12. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  13. use Symfony\Component\Config\Resource\FileResource;
  14. /**
  15. * Registers the additional validators according to the storage
  16. *
  17. * @author Christophe Coevoet <stof@notk.org>
  18. */
  19. class ValidationPass implements CompilerPassInterface
  20. {
  21. /**
  22. * {@inheritDoc}
  23. */
  24. public function process(ContainerBuilder $container)
  25. {
  26. if (!$container->hasParameter('fos_user.storage')) {
  27. return;
  28. }
  29. $storage = $container->getParameter('fos_user.storage');
  30. if ('custom' === $storage) {
  31. return;
  32. }
  33. if (!$container->hasParameter('validator.mapping.loader.xml_files_loader.mapping_files')) {
  34. return;
  35. }
  36. $files = $container->getParameter('validator.mapping.loader.xml_files_loader.mapping_files');
  37. $validationFile = __DIR__ . '/../../Resources/config/validation/' . $storage . '.xml';
  38. if (is_file($validationFile)) {
  39. $files[] = realpath($validationFile);
  40. $container->addResource(new FileResource($validationFile));
  41. }
  42. $container->setParameter('validator.mapping.loader.xml_files_loader.mapping_files', $files);
  43. }
  44. }