harbor/collections

通用集合类

2.0.3 2014-10-28 11:55 UTC

This package is auto-updated.

Last update: 2024-09-17 08:54:57 UTC


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());