goksagun/collection
Composer 安装命令:
composer require goksagun/collection
包简介
A PHP collection library providing functionalities for managing and manipulating collections.
README 文档
README
A PHP collection library providing functionalities for managing and manipulating product collections.
Features
- Create a collection of items
- Add a item to the collection
- Map over the collection to apply a function to each item
- Filter the collection based on a predicate
- Pluck a specific property from each item in the collection
- Reduce the collection to a single value
- Sort the collection based on a custom comparison function
Installation
Use Composer to install this library:
composer require goksagun/collection
Usage
Here's a basic example of how to use this library:
<?php namespace Acme; class Product { public function __construct ( private string $name, private float $price ) {} public function getName(): string { return $this->name; } public function getPrice(): float { return $this->price; } }
<?php namespace Acme; use Acme\Product; use Goksagun\Collection\Collection; /** * @implements Collection<Product> */ final class ProductCollection extends Collection { public function __construct(Product ...$items) { parent::__construct(...$items); } }
<?php namespace Acme; use Acme\Product; use Acme\ProductCollection; $collection = new ProductCollection( new Product('Product 1', 100.99), new Product('Product 2', 200.99), new Product('Product 3', 300.99), ); $total = $collection ->map(function (Product $product) { return new Product($product->getName(), $product->getPrice() * 1.18); }) ->each(function (\Goksagun\Collection\Test\Fixtures\Product $product, int $index) { echo "Product {$index}: {$product->getName()} - {$product->getPrice()}\n"; }) ->filter(function (Product $product) { return $product->getPrice() > 300; }) ->pluck('price') ->reduce(function (float $total, float $price) { return $total + $price; }, 0); echo "Total: {$total}\n"; // Product 0: Product 1 - 119.1682 // Product 1: Product 2 - 237.1682 // Product 2: Product 3 - 355.1682 // Product 0: Product 3 - 355.1682 // Total: 355.1682
Testing
Run the tests with:
composer test
License
This project is licensed under the MIT License - see the LICENSE file for details.
goksagun/collection 适用场景与选型建议
goksagun/collection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 130 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 04 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「product」 「library」 「management」 「sort」 「collection」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 goksagun/collection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 goksagun/collection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 goksagun/collection 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple RSS generator library for PHP 5.5 or later. clone from Bhaktaraz Bhatta ttps://github.com/bhaktaraz/php-rss-generator
Inbox pattern process implementation for your Laravel Applications
Display your categories and products on front end of your website
Product catalog for your Symfony2 applications.
SilverCommerce module that adds customisable products (adding dropdowns, radio buttons or textfields to a product)
Core library that defines common interfaces used by the rest of the intahwebz..
统计信息
- 总下载量: 130
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-04-21