natsumeaurlia / auto-property-reflection
Automatically reflect properties.
Installs: 31
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
pkg:composer/natsumeaurlia/auto-property-reflection
Requires
- php: ^7.4 || ^8.0
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^8.3 || ^9.1
This package is auto-updated.
Last update: 2025-12-16 12:08:20 UTC
README
Provide a simple property initialization. API resources can be easily represented.
Installation
composer require natsumeaurlia/auto-property-reflection
Usage
Extends from an abstract class. Define the required property names. This must be the same name as the key you accept.
class GithubUser extends PropertyReflector
{
public $id;
}
$user = new GithubUser(['id' => 'xxxx']);
$user->id;
If the property is not defined, it will not be set.
class GithubUser extends PropertyReflector
{
public $id;
}
$user = new GithubUser(['name' => 'xxxx']);
$user->name; // access undefined property
Example
class GithubUser extends PropertyReflector
{
public $name;
}
// cURL,Guzzle ...etc
$client = new GuzzleHttp\Client();
$res = $client->request('GET', 'https://api.github.com/users/octocat');
$user = new GithubUser($res->getBody()->getContents());
$user->name; // octocat