Unique.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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 Symfony\Bundle\DoctrineMongoDBBundle\Validator\Constraints;
  11. use Symfony\Component\Validator\Constraint;
  12. /**
  13. * Doctrine MongoDB ODM unique value constraint.
  14. *
  15. * @author Bulat Shakirzyanov <bulat@theopenskyproject.com>
  16. */
  17. class Unique extends Constraint
  18. {
  19. public $message = 'The value for {{ property }} already exists.';
  20. public $path;
  21. public $documentManager;
  22. public function getDefaultOption()
  23. {
  24. return 'path';
  25. }
  26. public function getRequiredOptions()
  27. {
  28. return array('path');
  29. }
  30. public function validatedBy()
  31. {
  32. return 'doctrine_odm.mongodb.unique';
  33. }
  34. public function getTargets()
  35. {
  36. return Constraint::CLASS_CONSTRAINT;
  37. }
  38. public function getDocumentManagerId()
  39. {
  40. $id = 'doctrine.odm.mongodb.document_manager';
  41. if (null !== $this->documentManager) {
  42. $id = sprintf('doctrine.odm.mongodb.%s_document_manager', $this->documentManager);
  43. }
  44. return $id;
  45. }
  46. }