Skip to content

Latest commit

 

History

History
62 lines (61 loc) · 1.21 KB

README.md

File metadata and controls

62 lines (61 loc) · 1.21 KB

Joole Reflector


Joole Reflector is used to work with the properties of objects, their changes and merges.

Getting Started


Download it with composer:

composer require zloynick/joole-reflector

Usage


Init your reflector class:

...
use joole\reflector\Reflector;
...

Build reflection object:


...
$reflectedClass = $reflector->buildFromObject($yourClass);
//OR
$reflectedClass = $reflector->buildFromObject(
    YourClass::class,// class as string
    [$constructorParams1, $constructorParams2],// Using for class constructor
);
...

Change private/protected properties:


...
$reflectedClass->getProperty('exampleProperty')->setValue($value);
// Notice: $value's type must be instance of property type
// or null if property nullable. "exampleProperty" is a property of
// your class, that had reflected.
...

Properties merging:


...
$reflector->merge($class, [
    'id' => $id,
    'value' => $value,
]);
// OR
$reflector->merge($class, $classFrom, [
    'id' => $id,
    'value',//if exists at $classFrom
]);
...