harbor/data-container

此软件包已被废弃,不再维护。作者建议使用https://github.com/harborphp/collections软件包。

通用集合类

2.0.3 2014-10-28 11:55 UTC

This package is auto-updated.

Last update: 2021-01-17 00:53:18 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());