felixdorn / property-accessor
使用优雅的助手读取不可访问的属性
1.0.1
2021-05-16 09:13 UTC
Requires
- php: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3
- pestphp/pest: ^0.3.8
- phpstan/phpstan: ^0.12.48
- symfony/var-dumper: ^5.2.0
This package is auto-updated.
Last update: 2024-09-16 16:49:45 UTC
README
安装
需要 PHP 8.0.0+
您可以通过 composer 安装此包
composer require felixdorn/property-accessor
用法
use function \Felix\PropertyAccessor\access; class Book { protected string $name = 'Harry Potter'; protected int $isbn = 44081224; } $object = new Book(); access($object, 'isbn'); // returns 44081224 // Properties are injected based on the parameter name passed to the function. access($object, function ($isbn, $name) { return $isbn . ' - ' . $name; }); // returns '44081124 - Harry Potter' access($object, ['isbn', 'name']); // returns ['isbn' => 44081224, 'name' => 'Harry Potter']
测试
composer test
属性访问器 由 Félix Dorn 创建,遵循 MIT 许可。