kdyby/doctrine-collections-readonly

Doctrine 实体集合的只读包装器,便于工作

v1.0.0 2017-05-18 20:11 UTC

This package is auto-updated.

Last update: 2024-09-22 03:39:33 UTC


README

此包提供了一个只读集合包装器的实现,因此您可以从实体中返回集合,而无需复制集合的内容,或将其对象状态暴露在控制之外。

Build Status Downloads this Month Latest stable Coverage Status

安装

安装 Kdyby/DoctrineCollectionsReadonly 的最佳方式是使用 Composer

$ composer require kdyby/doctrine-collections-readonly

用法

简单地将您的集合包装并返回。

public function getComments() : Collection
{
	return new ReadOnlyCollectionWrapper($this->comments);
}

现在您可以使用与往常一样使用的 Collection API,只是不能修改它 :)

主页 http://www.kdyby.org 和仓库 http://github.com/Kdyby/DoctrineCollectionsReadonly.