pragmarx/coollection
Composer 安装命令:
composer require pragmarx/coollection
包简介
Laravel Illuminate collection with objectified properties
关键字:
README 文档
README
Access collection items as objects properties
Coollection is Laravel's Illuminate\Collection repackaged to be used as all properties were objects:
$collection->name $collection->addresses->first()->street_name $collection->flatten()->cars->filter(function($car) { return $car->name == 'ferrari' })->last()->model $countries->where('name.common', 'United States')->first()->currency->name->english;
Tightenco\Collect
To be agnostic and have complete idependence from Laravel's, but also to allow it to be used in Laravel applications, this package extends Tightenco\Collect, developed by Matt Stauffer from Tighten.
Why?
Answering with a question: which one is easier to look at?
collect( collect( collect( collect( $collection['cars'] )->unique('constructor')['models'] )->last()['model'] )['colors'] )->first()['rgb']
or
$collection->cars->unique('constructor')->last()->model->colors->first()->rgb
Isn't this easier on the eyes?
collect($vimeo)->body->data->first()->metadata->connections->likes->total;
Or you prefer this one?
collect($vimeo)['body']['data'][0]['metadata']['connections']['likes']['total'];
Used with Laravel request it is useful, if you receive:
{"pagination":{"perPage":100,"pageNumber":1}}
You collect() it:
$input = coollect($request->all());
And you can just:
$input->pagination->perPage
Instead of:
$input->get('pagination')['perPage']
You can also use "dot notation" to get your items:
$input->get('pagination.perPage')
PHP Agnostic
This is an agnostic PHP package, an extraction of Illuminate\Support\Collection with all needed classes, interfaces and traits. For that if you wish just to use Illuminate's Collection, you just have to import the class Collection:
$collection = new IlluminateExtracted\Support\Collection(['my collection']);
or use the usual helper:
$collection = collect(['my collection']);
Documentation
It's Laravel's Collection, at full power, so you can check its docs. The only difference is that you can access items (array keys) as properties, like any other PHP object:
$collection->map($mapper)->reduce($reducer)->random()->address->street $this->sendThanks( $collection->where('full_name', 'Barack Obama')->addresses->random() ); $countries->where('name.common', 'United States')->first()->currency->symbol;
Install
Via Composer
$ composer require pragmarx/coollection
Usage
Instantiate, the class directly or using the helper:
$c = new Coollection(['first_name' => 'Barack Obama']); $c = coollect(['first_name' => 'Barack Obama']);
Then you use it as an object:
echo $c->first_name; // Barack Obama echo $c->flip()->barak_obama == 'first_name' ? 'true' : 'false'; // true
One word keys are case insensitive:
echo $c->rio; echo $c->RIO;
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email acr@antoniocarlosribeiro.com instead of using the issue tracker.
Credits
- This package is an extension of Tightenco\Collect, developed by Matt Stauffer from Tighten.
- Tightenco\Collect is an extraction of The Laravel Framework's Collection, created by Taylor Otwell.
- Package creator Antonio Carlos Ribeiro
- Contributors
License
The MIT License (MIT). Please see License File for more information.
pragmarx/coollection 适用场景与选型建议
pragmarx/coollection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.47M 次下载、GitHub Stars 达 94, 最近一次更新时间为 2017 年 10 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「collection」 「pragmarx」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pragmarx/coollection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pragmarx/coollection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pragmarx/coollection 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package provides type-safe extension of the laravel collection, forcing a single type of object.
Laravel Server & App Health Monitor and Notifier
Traits to build collections of specific objects
ItalyStrap Helpers
Froq! Collection.
Model and Collection classes
统计信息
- 总下载量: 3.47M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 98
- 点击次数: 15
- 依赖项目数: 13
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-29