-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
It would be cool if you could deserialize configuration sections into php objects.
An example of the desired code:
$configuration->get('foo.bar.favoriteperson')->as(Person::class)->eatSomething();The configuration section:
'favoriteperson' => [
'name' => 'Nathan',
'age' => 21,
]The person class:
class Person {
public $name;
public $age;
public function eatSomething()
{
...
}
}The ->as() function on the configuration object would take a class definition, and then serialize the section passed in ->get back into the class passed.
I'm not sure what method you would go about using to do this, possibly something along the lines of
Parse section array into JSON
Use JSON to deserialize it into a PHP Object
Cast that object to the class passed
Reactions are currently unavailable