mittax/objectcollection 问题修复 & 功能扩展

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

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

mittax/objectcollection

Composer 安装命令:

composer require mittax/objectcollection

包简介

A very simple library to handle object lists on php

README 文档

README

Helps you build typed lists with php >=7.0

Install

composer require mittax/objectcollection

Usage

Create a subclass of objectCollectionAbstract which adds a list of objects to the collection by the constructor

Here is a sample abstraction. Further have a look in Tests. There are some basic usages documented

<?php
/**
 * Created by PhpStorm.
 * User: pboethig
 * Date: 14.12.16
 * Time: 20:10
 */

namespace Mittax\MediaConverterBundle\Collection;
use Mittax\ObjectCollection\CollectionAbstract;

/**
 * Class StorageItem
 * @package Mittax\MediaConverterBundle\Collection
 */
class StorageItem extends CollectionAbstract
{

    /**
     * StorageItem constructor.
     * @param \Mittax\MediaConverterBundle\Entity\Storage\StorageItem[] $items
     */
    public function __construct(Array $items)
    {
        parent::__construct();

        foreach ($items as $item)
        {
            $this->add($item);
        }
    }

    /**
     * @param $filename
     * @return \Mittax\MediaConverterBundle\Entity\Storage\StorageItem[]
     */
    public function filterByFilename( string $filename) : Array
    {
        return $this->filterByPropertyNameAndValue('filename', $filename);
    }

    /**
     * @return \Mittax\MediaConverterBundle\Entity\Storage\StorageItem
     */
    public function getFirstItem() : \Mittax\MediaConverterBundle\Entity\Storage\StorageItem
    {
        return parent::getFirstItem();
    }

    /**
     * @return \Mittax\MediaConverterBundle\Entity\Storage\StorageItem[]
     */
    public function getAllItems() : Array
    {
        return parent::getAllItems();
    }
}

Use the abstraction

Just instanciate your abstraction subclass and pass an array with your object to the constructor. The resulting collection is typed of your context

        $items = [$fileStorageItem, $fileStorageItem1, $fileStorageItem1];

        $collection = new Collection\StorageItem($items);

        $collection->filter($fileStorageItem->getFilename());

The result is a typed list from type StorageItem

Run tests

phpunit

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-12-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固