zloynick/joole-reflector

安装: 32

依赖: 2

建议: 0

安全: 0

星星: 1

关注者: 1

分支: 0

开放问题: 0

类型:joole-component

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

This package is not auto-updated.

Last update: 2024-09-29 02:03:45 UTC


README


Joole Reflector 用于处理对象的属性、它们的变化和合并。

入门

使用 composer 下载它

composer require zloynick/joole-reflector

用法

初始化您的反射类

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

构建反射对象


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

更改私有/受保护的属性


...
$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.
...

属性合并


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