44
55namespace PHPModelGenerator \Model \Property ;
66
7+ use PHPModelGenerator \Exception \SchemaException ;
78use PHPModelGenerator \Model \SchemaDefinition \JsonSchema ;
89use PHPModelGenerator \Model \SchemaDefinition \ResolvedDefinitionsCollection ;
910use PHPModelGenerator \Model \Schema ;
1617 *
1718 * @package PHPModelGenerator\Model
1819 */
19- class PropertyProxy implements PropertyInterface
20+ class PropertyProxy extends AbstractProperty
2021{
2122 /** @var string */
2223 protected $ key ;
24+ /** @var string */
25+ protected $ name ;
2326 /** @var ResolvedDefinitionsCollection */
2427 protected $ definitionsCollection ;
2528
2629 /**
2730 * PropertyProxy constructor.
2831 *
32+ * @param string $name The name must be provided separately as the name is not bound to the structure of a
33+ * referenced schema. Consequently two properties with different names can refer an identical schema utilizing the
34+ * PropertyProxy. By providing a name to each of the proxies the resulting properties will get the correct names.
35+ * @param JsonSchema $jsonSchema
2936 * @param ResolvedDefinitionsCollection $definitionsCollection
30- * @param string $key
37+ * @param string $key
38+ *
39+ * @throws SchemaException
3140 */
32- public function __construct (ResolvedDefinitionsCollection $ definitionsCollection , string $ key )
33- {
41+ public function __construct (
42+ string $ name ,
43+ JsonSchema $ jsonSchema ,
44+ ResolvedDefinitionsCollection $ definitionsCollection ,
45+ string $ key
46+ ) {
47+ parent ::__construct ($ name , $ jsonSchema );
48+
3449 $ this ->key = $ key ;
3550 $ this ->definitionsCollection = $ definitionsCollection ;
3651 }
@@ -45,22 +60,6 @@ protected function getProperty(): PropertyInterface
4560 return $ this ->definitionsCollection ->offsetGet ($ this ->key );
4661 }
4762
48- /**
49- * @inheritdoc
50- */
51- public function getName (): string
52- {
53- return $ this ->getProperty ()->getName ();
54- }
55-
56- /**
57- * @inheritdoc
58- */
59- public function getAttribute (): string
60- {
61- return $ this ->getProperty ()->getAttribute ();
62- }
63-
6463 /**
6564 * @inheritdoc
6665 */
@@ -130,7 +129,9 @@ public function filterValidators(callable $filter): PropertyInterface
130129 */
131130 public function getOrderedValidators (): array
132131 {
133- return $ this ->getProperty ()->getOrderedValidators ();
132+ return array_map (function (PropertyValidatorInterface $ propertyValidator ): PropertyValidatorInterface {
133+ return $ propertyValidator ->withProperty ($ this );
134+ }, $ this ->getProperty ()->getOrderedValidators ());
134135 }
135136
136137 /**
@@ -146,15 +147,19 @@ public function addDecorator(PropertyDecoratorInterface $decorator): PropertyInt
146147 */
147148 public function resolveDecorator (string $ input , bool $ nestedProperty ): string
148149 {
149- return $ this ->getProperty ()->resolveDecorator ($ input , $ nestedProperty );
150+ foreach ($ this ->getProperty ()->getDecorators () as $ decorator ) {
151+ $ input = $ decorator ->decorate ($ input , $ this , $ nestedProperty );
152+ }
153+
154+ return $ input ;
150155 }
151156
152157 /**
153158 * @inheritdoc
154159 */
155- public function hasDecorators (): bool
160+ public function getDecorators (): array
156161 {
157- return $ this ->getProperty ()->hasDecorators ();
162+ return $ this ->getProperty ()->getDecorators ();
158163 }
159164
160165 /**
0 commit comments