antstudiocz/doctrine-collections-readonly

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

v2.0.0 2022-06-21 17:54 UTC

This package is not auto-updated.

Last update: 2024-09-12 02:30:38 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.