Skip to content

Joole Reflector allows you to change protected, as well as private properties of an object.

Notifications You must be signed in to change notification settings

ZloyNick/joole-reflector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
]);
...

About

Joole Reflector allows you to change protected, as well as private properties of an object.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages