Validator.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Gedmo\SoftDeleteable\Mapping;
  3. use Gedmo\Exception\InvalidMappingException;
  4. use Doctrine\Common\Persistence\Mapping\ClassMetadata;
  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. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  11. */
  12. class Validator
  13. {
  14. /**
  15. * List of types which are valid for timestamp
  16. *
  17. * @var array
  18. */
  19. public static $validTypes = array(
  20. 'date',
  21. 'date_immutable',
  22. 'time',
  23. 'time_immutable',
  24. 'datetime',
  25. 'datetime_immutable',
  26. 'datetimetz',
  27. 'datetimetz_immutable',
  28. 'timestamp',
  29. 'zenddate',
  30. );
  31. public static function validateField(ClassMetadata $meta, $field)
  32. {
  33. if ($meta->isMappedSuperclass) {
  34. return;
  35. }
  36. $fieldMapping = $meta->getFieldMapping($field);
  37. if (!in_array($fieldMapping['type'], self::$validTypes)) {
  38. throw new InvalidMappingException(sprintf('Field "%s" (type "%s") must be of one of the following types: "%s" in entity %s',
  39. $field,
  40. $fieldMapping['type'],
  41. implode(', ', self::$validTypes),
  42. $meta->name));
  43. }
  44. }
  45. }