zloynick/joole-reflector

Installs: 32

Dependents: 2

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Type:joole-component

v2.1.5 2022-03-05 12:51 UTC

This package is not auto-updated.

Last update: 2024-10-13 02:17:42 UTC


README


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