harbor / collections
通用集合类
2.0.3
2014-10-28 11:55 UTC
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: 4.1.*
README
通用集合实现。
该特性实现了以下接口的所有方法
- Harbor\Collections\CollectionInterface
- ArrayAccess
- Countable
- IteratorAggregate
- JsonSerializable
Harbor\Collections\Collection
类简单使用
特性并实现这些接口,同时添加了一个构造函数。
安装
composer require "harbor/collections:2.0.*"
要求
PHP 5.4+
使用
作为特性
<?php class Foo implements CollectionInterface, ArrayAccess, Countable, IteratorAggregate, JsonSerializable { use Harbor\Collections\CollectionTrait; } // Use it $foo = new Foo(); $foo->bar = 'bar';
作为对象
<?php use Harbor\Collections\CollectionInterface; class Foo { protected $data; public function __construct(CollectionInterface $data) { $this->data = $data; } } // Use it $foo = new Foo(new Collection());