Validator.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. 'time',
  22. 'datetime',
  23. 'datetimetz',
  24. 'timestamp',
  25. 'zenddate'
  26. );
  27. public static function validateField(ClassMetadata $meta, $field)
  28. {
  29. if ($meta->isMappedSuperclass) {
  30. return;
  31. }
  32. $fieldMapping = $meta->getFieldMapping($field);
  33. if (!in_array($fieldMapping['type'], self::$validTypes)) {
  34. throw new InvalidMappingException(sprintf('Field "%s" must be of one of the following types: "%s"',
  35. $fieldMapping['type'],
  36. implode(', ', self::$validTypes)));
  37. }
  38. }
  39. }