fschaechter/php-collection 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fschaechter/php-collection

Composer 安装命令:

composer require fschaechter/php-collection

包简介

A library for handling sets of data

README 文档

README

PHP-Collection is an easy to use library for handling sets of data with support for filtering, sorting and reducing the data sets.

The class Collection extends PHP's ArrayObject and so brings a little extra to the table.

Build Status

Installation

You can just clone the repository and use it as you see fit or use Composer and handle the dependency management very efficiently.

Composer

Append the following line to the require-key of your composer.json file.

"fschaechter/php-collection": "~2"

Issues and bugs

You can report bugs, problems and other issues here. Every useful bit is very much appreciated.

Tutorial

First you need a some data and create a collection.

<?php
$data = array(
    "Apple",
    "Apple,"
    "Pear",
    "Been",
    "Pear",
    "Strawberry",
);
$collection = new \Collection\Collection($data);

Append some more data.

<?php
$collection->append("Been");
$collection[] = "Pear";

Now you can just iterate over the data.

<?php
echo sprinft(
    "We have %s items." . PHP_EOL,
    count($collection)
);

foreach ($collection as $item) {
    echo $item . PHP_EOL;
}

It would be nice if the collection is sorted.

<?php
$comparator = new \Collection\Comparator\String();
$sorter = new \Collection\Sorter\Uasort($comparator);
$collection->sort($sorter);

foreach ($collection as $item) {
    echo $item . PHP_EOL;
}

We don't like apples.

<?php
$filter = new \Collection\Filter\Unequal("Apple");
$collection = $collection->filter($filter);

foreach ($collection as $item) {
    echo $item . PHP_EOL;
}

Let's distill the items.

<?php
$reducer = new \Collection\Reducer\Distinct();
$collection = $collection->reduce($reducer);

foreach ($collection as $item) {
    echo $item . PHP_EOL;
}

More examples

Take a look at the examples directory, there you will find three example of how to play with a collection.

  • Look at example_filter.php to see the filter system in action.
  • Look at example_reduce.php to see how a reducer melts away unwanted data.
  • Look at example_sort.php to see how you can sort a collection of objects.

Quality?

This library is developed under the principles of TDD. You can find all the tests within the tests directory. Check for yourself using PHPUnit.

$ bin/phpunit

Apache Ant is used for the complete build process. See build.xml, the file is based on the one you can find in PHPUnit's github.com repo.

$ ant

And Travis-CI makes sure its tested over and over again.

Tips and tricks

Enhance the PATH

All commands are installed to the bin directory by Composer. Add this directory to the environment path and there are easy accessible.

Here's an example for BASH, add the line to the ~/.bashrc.

PATH="./bin:$PATH"

Now it is very simple to run the unit tests.

$ phpunit

Instead of

$ bin/phpunit

So much more productivity gained.

Why?

I come across a lot of data in form of list almost daily and i need an easy, testable and pragmatic way to extract information of these lists.

License

This library is licensed under the terms of the GNU General Public License v3.

Whats new?

2.3.1 Updated documention.

Added Travis CI status image. Updated documentation.

2.3.0 Exceptions and a new filter.

Added exception classes. Added a new filter for simple filtering of arrays.

2.2.0 Enhanced collection.

Added isEmpty() to Collection, so you can check if the collection is empty or has some elements.

2.1.0 Enhanced collection.

Added method getFirst() to Collection. This makes it easier to access the first element of the collection.

2.0.1 Fixed example.

There was a bug in examples/example_sort.php.

2.0.0 Refactored comparators.

The comparators moved from the namespace \Collection\Sorter\Comparator to \Collection\Comparator. This changed the API incompatibly with the prior version 1.0.0.

1.0.0 Started library.

This is the initial project.

统计信息

  • 总下载量: 18
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 23
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2016-07-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固