Skip to content

Commit 4392d6f

Browse files
committed
Use $rawModelDataInput as construct function parameter name in Model.phptpl
Because when Symfony deserializer the object will not find the parameter value in the saved data and use the default parameter value(empty array). Then the model construct function will get error: `Typed property must not be accessed before initialization` since PHP 7.4 see: https://github.com/symfony/symfony/blob/44db49fb8f6d70c4341120a3f8f1b1a1a0dfa014/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php#L380 and https://github.com/symfony/symfony/blob/44db49fb8f6d70c4341120a3f8f1b1a1a0dfa014/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php#L355
1 parent ce2673d commit 4392d6f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Let's have a look into an easy example. We create a simple model for a person wi
102102
After generating a class with this JSON-Schema our class with the name `Person` will provide the following interface:
103103
```php
104104
// the constructor takes an array with data which is validated and applied to the model
105-
public function __construct(array $modelData);
105+
public function __construct(array $rawModelDataInput);
106106

107107
// the method getRawModelDataInput always delivers the raw input which was provided on instantiation
108108
public function getRawModelDataInput(): array;

src/Templates/Model.phptpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ class {{ class }} {% if schema.getInterfaces() %}implements {{ viewHelper.joinCl
4242
/**
4343
* {{ class }} constructor.
4444
*
45-
* @param array $modelData
45+
* @param array $rawModelDataInput
4646
*
4747
* @throws {% if generatorConfiguration.collectErrors() %}{{ viewHelper.getSimpleClassName(generatorConfiguration.getErrorRegistryClass()) }}{% else %}ValidationException{% endif %}
4848
*/
49-
public function __construct(array $modelData = [])
49+
public function __construct(array $rawModelDataInput = [])
5050
{
5151
{% if generatorConfiguration.collectErrors() %}
5252
$this->_errorRegistry = new {{ viewHelper.getSimpleClassName(generatorConfiguration.getErrorRegistryClass()) }}();
@@ -55,12 +55,12 @@ class {{ class }} {% if schema.getInterfaces() %}implements {{ viewHelper.joinCl
5555
{{ schemaHookResolver.resolveConstructorBeforeValidationHook() }}
5656

5757
{% if schema.getBaseValidators() %}
58-
$this->executeBaseValidators($modelData);
58+
$this->executeBaseValidators($rawModelDataInput);
5959
{% endif %}
6060

6161
{% foreach schema.getProperties() as property %}
6262
{% if not property.isInternal() %}
63-
$this->process{{ viewHelper.ucfirst(property.getAttribute()) }}($modelData);
63+
$this->process{{ viewHelper.ucfirst(property.getAttribute()) }}($rawModelDataInput);
6464
{% endif %}
6565
{% endforeach %}
6666

@@ -70,7 +70,7 @@ class {{ class }} {% if schema.getInterfaces() %}implements {{ viewHelper.joinCl
7070
}
7171
{% endif %}
7272

73-
$this->_rawModelDataInput = $modelData;
73+
$this->_rawModelDataInput = $rawModelDataInput;
7474

7575
{{ schemaHookResolver.resolveConstructorAfterValidationHook() }}
7676
}

0 commit comments

Comments
 (0)