ValidationPass.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. $validationFile = __DIR__ . '/../../Resources/config/storage-validation/' . $storage . '.xml';
  34. if ($container->hasDefinition('validator.builder')) {
  35. // Symfony 2.5+
  36. $container->getDefinition('validator.builder')
  37. ->addMethodCall('addXmlMapping', array($validationFile));
  38. return;
  39. }
  40. // Old method of loading validation
  41. if (!$container->hasParameter('validator.mapping.loader.xml_files_loader.mapping_files')) {
  42. return;
  43. }
  44. $files = $container->getParameter('validator.mapping.loader.xml_files_loader.mapping_files');
  45. if (is_file($validationFile)) {
  46. $files[] = realpath($validationFile);
  47. $container->addResource(new FileResource($validationFile));
  48. }
  49. $container->setParameter('validator.mapping.loader.xml_files_loader.mapping_files', $files);
  50. }
  51. }