-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathValidator.php
More file actions
61 lines (54 loc) · 1.71 KB
/
Validator.php
File metadata and controls
61 lines (54 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/*
* This file is part of the Doctrine Behavioral Extensions package.
* (c) Gediminas Morkevicius <gediminas.morkevicius@gmail.com> http://www.gediminasm.org
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Gedmo\SoftDeleteable\Mapping;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Gedmo\Exception\InvalidMappingException;
/**
* This class is used to validate mapping information
*
* @author Gustavo Falco <comfortablynumb84@gmail.com>
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
*
* @final since gedmo/doctrine-extensions 3.11
*/
class Validator
{
/**
* List of types which are valid for timestamp
*
* @var string[]
*/
public static $validTypes = [
'date',
'date_immutable',
'time',
'time_immutable',
'datetime',
'datetime_immutable',
'datetimetz',
'datetimetz_immutable',
'timestamp',
'date_point',
];
/**
* @param ClassMetadata<object> $meta
* @param mixed $field
*
* @return void
*/
public static function validateField(ClassMetadata $meta, $field)
{
if ($meta->isMappedSuperclass) {
return;
}
$fieldMapping = $meta->getFieldMapping($field);
if (!in_array($fieldMapping->type ?? $fieldMapping['type'], self::$validTypes, true)) {
throw new InvalidMappingException(sprintf('Field "%s" (type "%s") must be of one of the following types: "%s" in entity %s', $field, $fieldMapping->type ?? $fieldMapping['type'], implode(', ', self::$validTypes), $meta->getName()));
}
}
}