atournayre/collection 问题修复 & 功能扩展

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

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

atournayre/collection

最新稳定版本:0.8.1

Composer 安装命令:

composer require atournayre/collection

包简介

Collections library.

README 文档

README

This library provides a way to manipulate collections.

Installation

Use Composer to install the package:

composer require atournayre/collection

Collections

Method Description
TypedCollection::createAsList() Create a list from an array
TypedCollection::createAsMap() Create a map from an array
TypedCollectionImmutable::createAsList() Create an immutable list from an array
TypedCollectionImmutable::createAsMap() Create an immutable map from an array
DecimalValueCollection::fromArray() Create a collection of DecimalValue from an array
DecimalValuePrecisionConsistentCollection::fromArray() Create a collection of DecimalValue with precision consistent from an array

Examples

Typed Collection

// Samples classes
class Person
{
    public function __construct(
        public string $name
    ) {}
}

class People extends TypedCollection
{
    protected static string $type = Person::class;
}
// Create collection
$collection = People::createAsList([
    new Person('John'),
]);
$collection[] = new Person('Jack'); // Add item

Typed Collection Immutable

// Samples classes
class Person
{
    public function __construct(
        public string $name
    ) {}
}

class People extends TypedCollectionImmutable
{
    protected static string $type = Person::class;
}
// Create collection
$collection = People::createAsList([
    new Person('John'),
]);
$collection[] = new Person('Jack'); // Throws a RuntimeException

Decimal Collection

$collection = DecimalValueCollection::fromArray([
    DecimalValue::create(4.235, 3),
    DecimalValue::fromInt(1),
    DecimalValue::fromString('2'),
    DecimalValue::fromFloat(3.01, 2),
], 2);
$collection[0]->toFloat(); // 4.24
$collection[1]->toFloat(); // 1.00
$collection[2]->toFloat(); // 2.00
$collection[3]->toFloat(); // 3.01

Contribute

Contributions to the package are always welcome!

License

All contents of this package are licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固