lordmonoxide/collection
最新稳定版本:1.0.0
Composer 安装命令:
composer require lordmonoxide/collection
包简介
Powerful but easy to use collections with support for lazy loading
README 文档
README
Collection
A modular, trait-based collection library that puts control of your data back in your hands.
Installation
Composer
Composer is the recommended method of installation for Collection.
$ composer require lordmonoxide/collection
GitHub
Phi may be downloaded from GitHub.
Features
Basic Collection Use
Collections make it easy to control access to your data in an object-oriented way. The standard implementation supports
reading and writing, as well as standard foreach iteration.
$collection = new Collection(['k1' => 'v1']); var_dump($collection->get('k1')); // 'v1' var_dump($collection->size()); // 1 $collection->set('k2', 'v2'); $collection->add('v3'); // $collection == ['k1' => 'v1', 'k2' => 'v2', 'v3'] $collection->remove('k2'); // $collection == ['k1' => 'v1', 'v3'] foreach($collection as $k => $v) { // }
Custom Collections
Collections are built with traits, so it's easy to pick-and-choose the features you want. For example, you may want a collection that can't be modified from the outside:
class MyCollection implements ReadableCollectionInterface { use ReadableCollectionTrait; protected $collection = []; }
If you would like to implement a full read/write collection, you may extend the basic Collection class:
class MyCollection extends Collection { // }
Or, you may implement the interfaces and trait:
class MyCollection implements ReadableCollectionInterface, WritableCollectionInterface { use ReadableCollectionTrait, WritableCollectionTrait; }
Array Access
If you would like to use array access with your collection, use the ArrayAccessCollection class or the ArrayAccessCollectionTrait trait.
Lazy Loading
Writable collections have support for lazy-loading built in. Lazy loading can be very useful, for example, in database interactions.
$collection->lazy(1, function($key) { return User::find($key); });
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPLv3
- 更新时间: 2015-05-19