simplecomplex/explorable
Composer 安装命令:
composer require simplecomplex/explorable
包简介
Foreach'ing protected members made simple
README 文档
README
composer namespace: simplecomplex/explorable
Foreach'ing protected members made simple
An interface, base class and traits making it a breeze to expose a class' protected members.
Extending Explorable facilitates:
isset()count()foreach (...var_dump()toObject(),toArray()json_encode()
Usage
Class declaring it's properties
Property names hardcoded in constant EXPLORABLE_VISIBLE.
<?php use SimpleComplex\Explorable\Explorable; use SimpleComplex\Explorable\ExplorableTrait; /** * @property-read string $foo * @property-read string $bar */ class ExplorablesDeclared extends Explorable { use ExplorableTrait; public const EXPLORABLE_VISIBLE = [ 'foo' => true, 'bar' => true, ]; protected string $foo; protected string $bar; }
Class relying on property table discovery
The properties will be discovered on-demand, via explorablePrepare().
All instance vars must be nullable and declared as null
(protected ?string $foo = null;).
Otherwise risk of getting "::$foo must not be accessed before initialization"
error, or the instance vars simply won't get discovered (because not set to a
value (null)).
<?php use SimpleComplex\Explorable\Explorable; use SimpleComplex\Explorable\ExplorableTrait; /** * @property-read string $foo * @property-read string $bar */ class ExplorablesDiscoverable extends Explorable { use ExplorableTrait; protected ?string $foo = null; protected ?string $bar = null; }
MIT licensed
License and copyright. Explained.
Requirements
- PHP ^7.4 || ^8.0
Development (require-dev)
- phpunit ^8 || ^9
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-04-19