programster/collections 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

programster/collections

最新稳定版本:1.1.0

Composer 安装命令:

composer require programster/collections

包简介

A simple library to simplify the creation of strict type arrays/collections.

README 文档

README

A package to simplify the creation of strict type arrays in PHP.

Example Usage

The example below creates a collection of users and sorts them by their name.

<?php

require_once(__DIR__ . '/vendor/autoload.php');

class User
{
    public function __construct(public readonly string $name){}
}

class UserCollection extends \Programster\Collections\AbstractCollection
{
    public function __construct(User ...$elements)
    {
        parent::__construct(User::class, ...$elements);
    }
}

$names = new UserCollection(
    new User("Programster"),
    new User("Bar"),
    new User("Foo"),
);

// Demonstrate that can append a user, like with a normal array.
$names[] = new User("Added User");

$sortByNameFunc = function(User $name1, User $name2){
    return $name1->name <=> $name2->name;
};

$names->uasort($sortByNameFunc);
print "Users sorted by name: " . print_r($names, true) . PHP_EOL;

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-18