|
1 |
| -<?php |
2 |
| - |
3 |
| -declare(strict_types = 1); |
4 |
| - |
5 |
| -namespace PHPModelGenerator\Model; |
6 |
| - |
7 |
| -use Exception; |
8 |
| -use PHPModelGenerator\Exception\SchemaException; |
9 |
| -use PHPModelGenerator\Model\Property\Property; |
10 |
| -use PHPModelGenerator\Model\Property\PropertyInterface; |
11 |
| -use PHPModelGenerator\Model\SchemaDefinition\SchemaDefinitionDictionary; |
12 |
| -use PHPModelGenerator\Model\Validator\PropertyValidator; |
13 |
| -use PHPModelGenerator\Model\Validator\PropertyValidatorInterface; |
14 |
| - |
15 |
| -/** |
16 |
| - * Class Schema |
17 |
| - * |
18 |
| - * @package PHPModelGenerator\Model |
19 |
| - */ |
20 |
| -class Schema |
21 |
| -{ |
22 |
| - /** @var string */ |
23 |
| - protected $className; |
24 |
| - /** @var Property[] The properties which are part of the class */ |
25 |
| - protected $properties = []; |
26 |
| - /** @var PropertyValidator[] A Collection of validators which must be applied |
27 |
| - * before adding properties to the model |
28 |
| - */ |
29 |
| - protected $baseValidators = []; |
30 |
| - /** @var SchemaDefinitionDictionary */ |
31 |
| - protected $schemaDefinitionDictionary; |
32 |
| - |
33 |
| - /** |
34 |
| - * Schema constructor. |
35 |
| - * |
36 |
| - * @param string $className |
37 |
| - * @param SchemaDefinitionDictionary $dictionary |
38 |
| - */ |
39 |
| - public function __construct(string $className, SchemaDefinitionDictionary $dictionary = null) |
40 |
| - { |
41 |
| - $this->className = $className; |
42 |
| - $this->schemaDefinitionDictionary = $dictionary ?? new SchemaDefinitionDictionary(''); |
43 |
| - } |
44 |
| - |
45 |
| - /** |
46 |
| - * @return string |
47 |
| - */ |
48 |
| - public function getClassName(): string |
49 |
| - { |
50 |
| - return $this->className; |
51 |
| - } |
52 |
| - |
53 |
| - /** |
54 |
| - * @return PropertyInterface[] |
55 |
| - */ |
56 |
| - public function getProperties(): array |
57 |
| - { |
58 |
| - return $this->properties; |
59 |
| - } |
60 |
| - |
61 |
| - /** |
62 |
| - * @param PropertyInterface $property |
63 |
| - * |
64 |
| - * @return $this |
65 |
| - */ |
66 |
| - public function addProperty(PropertyInterface $property): self |
67 |
| - { |
68 |
| - if (!isset($this->properties[$property->getName()])) { |
69 |
| - $this->properties[$property->getName()] = $property; |
70 |
| - } |
71 |
| - |
72 |
| - return $this; |
73 |
| - } |
74 |
| - |
75 |
| - /** |
76 |
| - * @return PropertyValidator[] |
77 |
| - */ |
78 |
| - public function getBaseValidators(): array |
79 |
| - { |
80 |
| - return $this->baseValidators; |
81 |
| - } |
82 |
| - |
83 |
| - /** |
84 |
| - * @param PropertyValidatorInterface $baseValidator |
85 |
| - * |
86 |
| - * @return $this |
87 |
| - */ |
88 |
| - public function addBaseValidator(PropertyValidatorInterface $baseValidator) |
89 |
| - { |
90 |
| - $this->baseValidators[] = $baseValidator; |
91 |
| - |
92 |
| - return $this; |
93 |
| - } |
94 |
| - |
95 |
| - /** |
96 |
| - * @return SchemaDefinitionDictionary |
97 |
| - */ |
98 |
| - public function getSchemaDictionary(): SchemaDefinitionDictionary |
99 |
| - { |
100 |
| - return $this->schemaDefinitionDictionary; |
101 |
| - } |
102 |
| -} |
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types = 1); |
| 4 | + |
| 5 | +namespace PHPModelGenerator\Model; |
| 6 | + |
| 7 | +use Exception; |
| 8 | +use PHPModelGenerator\Exception\SchemaException; |
| 9 | +use PHPModelGenerator\Model\Property\Property; |
| 10 | +use PHPModelGenerator\Model\Property\PropertyInterface; |
| 11 | +use PHPModelGenerator\Model\SchemaDefinition\SchemaDefinitionDictionary; |
| 12 | +use PHPModelGenerator\Model\Validator\PropertyValidator; |
| 13 | +use PHPModelGenerator\Model\Validator\PropertyValidatorInterface; |
| 14 | + |
| 15 | +/** |
| 16 | + * Class Schema |
| 17 | + * |
| 18 | + * @package PHPModelGenerator\Model |
| 19 | + */ |
| 20 | +class Schema |
| 21 | +{ |
| 22 | + /** @var string */ |
| 23 | + protected $className; |
| 24 | + /** @var string */ |
| 25 | + protected $classPath; |
| 26 | + /** @var Property[] The properties which are part of the class */ |
| 27 | + protected $properties = []; |
| 28 | + /** @var PropertyValidator[] A Collection of validators which must be applied |
| 29 | + * before adding properties to the model |
| 30 | + */ |
| 31 | + protected $baseValidators = []; |
| 32 | + /** @var array */ |
| 33 | + protected $usedClasses = []; |
| 34 | + |
| 35 | + /** @var SchemaDefinitionDictionary */ |
| 36 | + protected $schemaDefinitionDictionary; |
| 37 | + |
| 38 | + /** |
| 39 | + * Schema constructor. |
| 40 | + * |
| 41 | + * @param string $classPath |
| 42 | + * @param string $className |
| 43 | + * @param SchemaDefinitionDictionary $dictionary |
| 44 | + */ |
| 45 | + public function __construct(string $classPath, string $className, SchemaDefinitionDictionary $dictionary = null) |
| 46 | + { |
| 47 | + $this->className = $className; |
| 48 | + $this->classPath = $classPath; |
| 49 | + $this->schemaDefinitionDictionary = $dictionary ?? new SchemaDefinitionDictionary(''); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @return string |
| 54 | + */ |
| 55 | + public function getClassName(): string |
| 56 | + { |
| 57 | + return $this->className; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * @return string |
| 62 | + */ |
| 63 | + public function getClassPath(): string |
| 64 | + { |
| 65 | + return $this->classPath; |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * @return PropertyInterface[] |
| 70 | + */ |
| 71 | + public function getProperties(): array |
| 72 | + { |
| 73 | + return $this->properties; |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * @param PropertyInterface $property |
| 78 | + * |
| 79 | + * @return $this |
| 80 | + */ |
| 81 | + public function addProperty(PropertyInterface $property): self |
| 82 | + { |
| 83 | + if (!isset($this->properties[$property->getName()])) { |
| 84 | + $this->properties[$property->getName()] = $property; |
| 85 | + } |
| 86 | + |
| 87 | + return $this; |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * @return PropertyValidator[] |
| 92 | + */ |
| 93 | + public function getBaseValidators(): array |
| 94 | + { |
| 95 | + return $this->baseValidators; |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * @param PropertyValidatorInterface $baseValidator |
| 100 | + * |
| 101 | + * @return $this |
| 102 | + */ |
| 103 | + public function addBaseValidator(PropertyValidatorInterface $baseValidator) |
| 104 | + { |
| 105 | + $this->baseValidators[] = $baseValidator; |
| 106 | + |
| 107 | + return $this; |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * @return SchemaDefinitionDictionary |
| 112 | + */ |
| 113 | + public function getSchemaDictionary(): SchemaDefinitionDictionary |
| 114 | + { |
| 115 | + return $this->schemaDefinitionDictionary; |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Add a class to the schema which is required |
| 120 | + * |
| 121 | + * @param string $path |
| 122 | + * |
| 123 | + * @return $this |
| 124 | + */ |
| 125 | + public function addUsedClass(string $path): self |
| 126 | + { |
| 127 | + $this->usedClasses[] = $path; |
| 128 | + |
| 129 | + return $this; |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * @return array |
| 134 | + */ |
| 135 | + public function getUsedClasses(): array |
| 136 | + { |
| 137 | + return $this->usedClasses; |
| 138 | + } |
| 139 | +} |
0 commit comments