定制 tandiljuan/collection 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

tandiljuan/collection

Composer 安装命令:

composer require tandiljuan/collection

包简介

PHP library to create custom collections

README 文档

README

PHP library to create custom collections.

Usage

Define a custom collection, extending library's abstract collection and defining the item and offset types

<?php

class MyCustomCollection extends \Tandiljuan\Collection\AbstractCollection
{
    /**
     * {@inheritdoc}
     */
    protected $itemType = '\DateTime';

    /**
     * {@inheritdoc}
     */
    protected $offsetType = 'integer';
}

Create a collection that only will allow the item and offset types you have defined

<?php

$collection = new MyCustomCollection();

try {
    $collection[] = 'error';
} catch (\Tandiljuan\Collection\Exception\InvalidItemType $e) {
    echo "Invalid item type\n";
}

try {
    $collection['a'] = new \DateTime();
} catch (\Tandiljuan\Collection\Exception\InvalidOffsetType $e) {
    echo "Invalid offset type\n";
}

$collection[] = new DateTime('2001-01-01 01:01:01');
$collection[] = new DateTime('2002-02-02 02:02:02');
$collection[] = new DateTime('2003-03-03 03:03:03');

Require parameters to be of MyCustomCollection using type declarations

<?php

function printItems(MyCustomCollection $parameter)
{
    foreach ($parameter as $item) {
        echo $item->format('r')."\n";
    }
}

printItems($collection);

// The output will be
// Mon, 01 Jan 2001 01:01:01 +0000
// Sat, 02 Feb 2002 02:02:02 +0000
// Mon, 03 Mar 2003 03:03:03 +0000

Development

Contributions must follow Symfony Coding Standards.

It's encouraged to read the following documentation:

The run bash script is a wrapper of a php docker container. It will bootstrap the container and run a given command inside of it. The container should have all needed tools for development. Please, let know the project maintainer if something is missing.

To add new packages in the composer.json file, use composer require

./run composer require [--dev] [vendor/package:version]

To install packages defined in the composer.json file, use composer install

./run composer install

To check PHP code against coding standards, use php-cs-fixer

# Check if a file needs to be fixed
./run php-cs-fixer fix --dry-run --diff path/to/file.php
# Fix a file
./run php-cs-fixer fix path/to/file.php

To run PHP REPL interactive shell, use php or psysh

# Using PHP
./run php -a
# Using psysh
./run psysh

Testing

Bootstrap Codeception test environment. This must be done only once.

$ # Bootstrap codeception without the standard suites
$ ./run codecept bootstrap --empty --namespace 'Tandiljuan\Collection\Tests'

Create a codeception test suit. This must be done only once per suit.

$ # Create `unit` suit (for unit testing)
$ ./run codecept generate:suite unit

Create a Cest class under a given suit. Can create as many Cest classes as needed.

$ # Create a new cest `Dummy` under the `unit` suit
$ ./run codecept generate:cest unit Dummy

After writing the tests, can execute them using the run command

$ ./run codecept run

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固