Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request #15020: REST representations can be hydrated even when they define a constructor #1

Merged
merged 1 commit into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"bshaffer/oauth2-server-php":"If you want to use OAuth2 for authentication"
},
"require":{
"php":">=7.2"
"php":">=7.2",
"doctrine/instantiator":"^1.3"
},
"require-dev":{
"guzzlehttp/guzzle":"3.8.1",
Expand Down
6 changes: 5 additions & 1 deletion vendor/Luracast/Restler/Data/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,11 @@ public static function validate($input, ValidationInfo $info, $full = null)
);
}
$class = $info->type;
$instance = new $class();
static $instantiator = null;
if ($instantiator === null) {
$instantiator = new \Doctrine\Instantiator\Instantiator();
}
$instance = $instantiator->instantiate($class);
if (is_array($info->children)) {
if (
empty($input) ||
Expand Down
6 changes: 5 additions & 1 deletion vendor/Luracast/Restler/Data/ValueObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public function __toString()
public static function __set_state(array $properties)
{
$class = get_called_class();
$instance = new $class ();
static $instantiator = null;
if ($instantiator === null) {
$instantiator = new \Doctrine\Instantiator\Instantiator();
}
$instance = $instantiator->instantiate($class);
$vars = get_object_vars($instance);
foreach ($properties as $property => $value) {
if (property_exists($instance, $property)) {
Expand Down
18 changes: 15 additions & 3 deletions vendor/Luracast/Restler/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ protected function _getBody()
continue;
if (class_exists($values->dataType)) {
$myClassName = $values->dataType;
$defaultObject->$name = new $myClassName();
$defaultObject->$name = self::instantiateClass($myClassName);
} else {
$defaultObject->$name = '';
}
Expand All @@ -706,9 +706,10 @@ protected function _model($className, $instance = null)
}
$properties = array();
if (!$instance) {
if (!class_exists($className))
if (!class_exists($className)) {
return;
$instance = new $className();
}
$instance = self::instantiateClass($className);
}
$data = get_object_vars($instance);
$reflectionClass = new \ReflectionClass($className);
Expand Down Expand Up @@ -1003,4 +1004,15 @@ protected function verifyAccess($route)
}
return true;
}

private static function instantiateClass(string $class)
{
static $instantiator = null;
if ($instantiator === null) {
$instantiator = new \Doctrine\Instantiator\Instantiator();
}
return $instantiator->instantiate($className);
}


}