1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
namespace AlgoWeb\ODataMetadata\Csdl\Internal\Serialization; |
7
|
|
|
|
8
|
|
|
use AlgoWeb\ODataMetadata\Edm\Validation\EdmError; |
9
|
|
|
use AlgoWeb\ODataMetadata\Edm\Validation\EdmErrorCode; |
10
|
|
|
use AlgoWeb\ODataMetadata\Edm\Validation\EdmValidator; |
11
|
|
|
use AlgoWeb\ODataMetadata\Edm\Validation\Internal\ValidationHelper; |
12
|
|
|
use AlgoWeb\ODataMetadata\Edm\Validation\ValidationRuleSet; |
13
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\IModel; |
14
|
|
|
|
15
|
|
|
abstract class SerializationValidator |
16
|
|
|
{ |
17
|
|
|
private static function getSerializationRuleSet(): ValidationRuleSet |
18
|
|
|
{ |
19
|
|
|
return new ValidationRuleSet([]); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param IModel $root |
24
|
|
|
* @throws \ReflectionException |
25
|
|
|
* @return array |
26
|
|
|
*/ |
27
|
|
|
public static function getSerializationErrors(IModel $root): array |
28
|
|
|
{ |
29
|
|
|
$errors = []; |
30
|
|
|
EdmValidator::validate($root, self::getSerializationRuleSet(), $errors); |
31
|
|
|
$errors = array_filter($errors, [self::class, 'significantToSerialization']); |
32
|
|
|
return $errors; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param EdmError $error |
37
|
|
|
* @return bool |
38
|
|
|
*/ |
39
|
|
|
private static function significantToSerialization(EdmError $error) |
40
|
|
|
{ |
41
|
|
|
if (ValidationHelper::isInterfaceCritical($error)) { |
42
|
|
|
return true; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
switch ($error->getErrorCode()) { |
46
|
|
|
case EdmErrorCode::InvalidName(): |
47
|
|
|
case EdmErrorCode::NameTooLong(): |
48
|
|
|
case EdmErrorCode::InvalidNamespaceName(): |
49
|
|
|
case EdmErrorCode::SystemNamespaceEncountered(): |
50
|
|
|
case EdmErrorCode::RowTypeMustNotHaveBaseType(): |
51
|
|
|
case EdmErrorCode::ReferencedTypeMustHaveValidName(): |
52
|
|
|
case EdmErrorCode::FunctionImportEntitySetExpressionIsInvalid(): |
53
|
|
|
case EdmErrorCode::FunctionImportParameterIncorrectType(): |
54
|
|
|
case EdmErrorCode::OnlyInputParametersAllowedInFunctions(): |
55
|
|
|
case EdmErrorCode::InvalidFunctionImportParameterMode(): |
56
|
|
|
case EdmErrorCode::TypeMustNotHaveKindOfNone(): |
57
|
|
|
case EdmErrorCode::PrimitiveTypeMustNotHaveKindOfNone(): |
58
|
|
|
case EdmErrorCode::PropertyMustNotHaveKindOfNone(): |
59
|
|
|
case EdmErrorCode::TermMustNotHaveKindOfNone(): |
60
|
|
|
case EdmErrorCode::SchemaElementMustNotHaveKindOfNone(): |
61
|
|
|
case EdmErrorCode::EntityContainerElementMustNotHaveKindOfNone(): |
62
|
|
|
case EdmErrorCode::BinaryValueCannotHaveEmptyValue(): |
63
|
|
|
case EdmErrorCode::EnumMustHaveIntegerUnderlyingType(): |
64
|
|
|
case EdmErrorCode::EnumMemberTypeMustMatchEnumUnderlyingType(): |
65
|
|
|
return true; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return false; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|