gamee/php-collections

PHP 有用集合的包

v4.3.0 2023-10-23 17:48 UTC

README

Latest Stable Version License Total Downloads Build Status

php-collections

有用的PHP工具(集合、迭代器等)

UniqueObjectCollection 使用

use Gamee\Collections\Collection\UniqueObjectCollection;

/**
 * @extends UniqueObjectCollection<UserData>
 */
final class UserDataCollection extends UniqueObjectCollection
{

	/**
	 * @param UserData $item
	 * @return string|int
	 */
	protected function getIdentifier(object $item)
	{
		return $item->getId();
	}
}

ObjectIterator 使用

use Gamee\Collections\Iterator\ObjectIterator;

class UserCredentialsDataIterator extends ObjectIterator
{

	public function current(): UserCredentialsData
	{
		return parent::current();
	}
}

ImmutableObjectCollection

use Gamee\Collections\Collection\ImmutableObjectCollection;

final class UserDataCollection extends ImmutableObjectCollection
{

	protected function getItemType(): string
	{
		return UserData::class;
	}


	public function current(): UserData
	{
		return parent::current();
	}
}