Validator.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Gedmo\SoftDeleteable\Mapping;
  3. use Doctrine\ORM\Mapping\ClassMetadataInfo;
  4. use Gedmo\Exception\InvalidMappingException;
  5. /**
  6. * This class is used to validate mapping information
  7. *
  8. * @author Gustavo Falco <comfortablynumb84@gmail.com>
  9. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  10. * @package Gedmo.SoftDeleteable.Mapping
  11. * @subpackage Validator
  12. * @link http://www.gediminasm.org
  13. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  14. */
  15. class Validator
  16. {
  17. /**
  18. * List of types which are valid for timestamp
  19. *
  20. * @var array
  21. */
  22. public static $validTypes = array(
  23. 'date',
  24. 'time',
  25. 'datetime',
  26. 'timestamp',
  27. 'zenddate'
  28. );
  29. public static function validateField(ClassMetadataInfo $meta, $field)
  30. {
  31. if ($meta->isMappedSuperclass) {
  32. return;
  33. }
  34. $fieldMapping = $meta->getFieldMapping($field);
  35. if (!in_array($fieldMapping['type'], self::$validTypes)) {
  36. throw new InvalidMappingException(sprintf('Field "%s" must be of one of the following types: "%s"',
  37. $fieldMapping['type'],
  38. implode(', ', self::$validTypes)));
  39. }
  40. }
  41. }