letsgoi/custom-list
最新稳定版本:2.3.0
Composer 安装命令:
composer require letsgoi/custom-list
包简介
PHP Custom List package
README 文档
README
Class to wrap array of items to force same type. This is for avoid the php array type hinting problem.
Requirements
- PHP >= 8.2
Usage
Extends the CustomList abstract class and set the type of the items with getListType method:
use Letsgoi\CustomList\CustomList; class ItemList extends CustomList { protected function getListType(): string { return Item::class; } } // $items = [new Item(), new Item(), ...]; $list = new ItemList($items);
To iterate items:
foreach ($list as $item) { // }
You can use the list as an array (set, get, ...)
Available methods
get($key = null)
Return item by key or all list without it:
$list->get(0); // 'item' $list->get(); // ['item', 'item', ...]
add($item)
Append item to list:
$list->add($item);
merge(... $customLists)
Merges the elements of one or more custom lists together
$list->merge($list1, $list2 ...);
Testing
Run tests:
composer test
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
统计信息
- 总下载量: 5.51k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-10-19