定制 letsgoi/custom-list 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

MIT

统计信息

  • 总下载量: 5.51k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 4
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-10-19