cora / collection
使用灵活的访问方法来保存数据集合。
v1.0.1
2019-08-15 17:30 UTC
Requires
- php: >=5.3.0
- phpunit/phpunit: 7.*
This package is auto-updated.
Last update: 2024-09-16 04:31:36 UTC
README
基本用法
灵活的接口,允许您使用您喜欢的格式
$collection = new \Cora\Collection(); $collection->add('Hello World'); echo $collection->get(0); // Outputs "Hello World" echo $collection[0]; // Outputs "Hello World" echo $collection->get("off0"); // Outputs "Hello World" echo $collection->off0; // Outputs "Hello World"
使用WHERE方法轻松过滤内容
$collection = new \Cora\Collection([ new \Classes\Event('Debit', '10/10/1980'), new \Classes\Event('Debit', '10/10/2001'), new \Classes\Event('Deposit', '02/14/2008'), new \Classes\Event('Debit', '10/10/1990'), new \Classes\Event('Debit', '10/10/2003'), new \Classes\Event('Deposit', '02/14/2004') ]); $this->assertEquals(6, $collection->count()); $this->assertEquals(4, count($collection->where('name', 'Debit'))); $this->assertEquals(2, count($collection->where('name', 'Deposit'))); $this->assertEquals(4, count($collection->where('timestamp', new \DateTime('01/01/2000'), '>=')));
可以将对象属性或关联数组键设置为访问的主键
这里我们将 "name" 作为第二个构造函数参数传递
$collection = new \Cora\Collection([ new \Classes\User('User1', 'Type1'), new \Classes\User('User2', 'Type1'), new \Classes\User('User3', 'Type2'), new \Classes\User('User4', 'Type2'), new \Classes\User('User5', 'Type1'), new \Classes\User('User6', 'Type3') ], 'name'); $this->assertEquals('User3', $collection->User3->name); $this->assertEquals('Type2', $collection->User3->type); $this->assertEquals('Type2', $collection->get('User3')->type);
等等...
支持合并、映射、过滤、排序、分组、最小值、最大值、求和、计数等。
运行测试
如果您有Docker,您可以从命令行下载项目并运行 docker-compose up
。然后从命令行运行 ./App/phpunit.sh tests
。
文档
有关完整文档,请参阅GitHub页面网站: http://joebubna.github.io/Cora/
关于Cora
Cora是一组用于快速应用程序开发的灵活工具。
许可证
Cora框架在MIT许可证下发布。