-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathCompositionPropertyDecorator.php
More file actions
84 lines (71 loc) · 2.29 KB
/
CompositionPropertyDecorator.php
File metadata and controls
84 lines (71 loc) · 2.29 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
declare(strict_types=1);
namespace PHPModelGenerator\Model\Property;
use PHPModelGenerator\Exception\SchemaException;
use PHPModelGenerator\Model\SchemaDefinition\JsonSchema;
use PHPModelGenerator\Model\SchemaDefinition\ResolvedDefinitionsCollection;
/**
* Class CompositionPropertyDecorator
*
* @package PHPModelGenerator\Model\Property
*/
class CompositionPropertyDecorator extends PropertyProxy
{
private const string PROPERTY_KEY = 'composition';
/**
* Store all properties from nested schemas of the composed property validator. If the composition validator fails
* all affected properties must be set to null to adopt only valid values in the base model.
*
* @var PropertyInterface[]
*/
protected $affectedObjectProperties = [];
private bool $alwaysTrueBranch = false;
/**
* CompositionPropertyDecorator constructor.
*
* @throws SchemaException
*/
public function __construct(string $propertyName, JsonSchema $jsonSchema, PropertyInterface $property)
{
parent::__construct(
$propertyName,
$jsonSchema,
new ResolvedDefinitionsCollection([self::PROPERTY_KEY => $property]),
self::PROPERTY_KEY,
);
$property->onResolve(function (): void {
$this->resolve();
});
}
/**
* Append an object property which is affected by the composition validator
*/
public function appendAffectedObjectProperty(PropertyInterface $property): void
{
$this->affectedObjectProperties[] = $property;
}
/**
* @return PropertyInterface[]
*/
public function getAffectedObjectProperties(): array
{
return $this->affectedObjectProperties;
}
public function markAsAlwaysTrueBranch(): void
{
$this->alwaysTrueBranch = true;
}
public function isAlwaysTrueBranch(): bool
{
return $this->alwaysTrueBranch;
}
/**
* Return the branch-level JSON schema (the composition element schema, which may contain
* additionalProperties constraints). This is distinct from getJsonSchema(), which proxies
* to the inner wrapped property's schema via PropertyProxy.
*/
public function getBranchSchema(): JsonSchema
{
return $this->jsonSchema;
}
}