francalek/datatype

PHP 使用的有用数据类型。

v0.1 2022-07-06 15:17 UTC

This package is auto-updated.

Last update: 2024-09-16 17:52:36 UTC


README

要求

此包与 PHP >= 7.1 兼容

安装

安装此包的最佳方法是使用 Composer

$ composer require francalek/datatype

使用方法

CountableIterator

此抽象类仅实现了 \Countable\Iterator 接口,并有自己的存储。

迭代和计数的必须数据应放在受保护的属性 $this->countableIterator 中。

use Francalek\DataType\CountableIterator;

class Sheeps extends CountableIterator
{
	public function __construct(int $sheeps = 5)
	{
		$herd = array_fill(0, $sheeps, 'Sheep');
		$this->countableIterator = $herd;
	}
}

现在您可以迭代您的类

echo "I can't sleep :(\n";

$sheeps = new Sheeps();
foreach ($sheeps as $nr => $sheep) {
	echo $sheep.' '.(++$nr)."\n";
}

exit("Chrrr...\n");

或者计数

echo "I can't sleep :(\n";

$sheeps = new Sheeps();
echo "I have ".count($sheeps)." sheeps in total.\n";

exit("Chrrr...\n");

运行测试

要运行测试

$ git clone https://github.com/francalek/DataType.git
$ cd DataType/
$ ./tests/run.sh

# Or over Composer
$ composer tests

贡献

  • 如果您发现了错误或对新增功能有想法,您可以创建 新问题
  • 在此存储库上分叉 以开始添加新功能、修复错误或创建更多测试。
  • 不要忘记发送拉取请求以将您的更改包含到此包中。
  • 阅读 贡献指南 的完整文本。

许可协议

此包受 MIT 许可协议 的许可。