承接 softboxlab/php-collection-helper 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

softboxlab/php-collection-helper

Composer 安装命令:

composer require softboxlab/php-collection-helper

包简介

Simple array and object-oriented collection

README 文档

README

Build Status codecov

Simple PHP Collection and array helper

Simple collection class to work with arrays on object-oriented paradigm and some array (collection) helpers with standardization of the parameters (data first, callback later, like javascript).

Collection

In this definition, our collection is Immutable, which means that every operation should return a new collection, keeping the original collection intact.

$collection = new Collection([1, 2, 3, 4]);
$newCollection = $collection->map(function ($item) {
    return $item * 2;
});

print_r($newCollection->all()); // [2, 4, 6, 8]
print_r($collection->all()); // [1, 2, 3, 4]

Collection helper

This is the base support to the Collection class. All the methods are implemented here.

List of available methods

  • map($data, $callback ($value, $key));
    • Map all the items of data with the provided callback. The callback will receive both value's and key's of the array.
  • filter($data, $callback($value, $key), $keepKeys);
    • Filter the given array with the provided callback. Only the items when the callback return's true will be returned on the filtered data. If false is passed to keepKeys parameter, the keys will be reseted.
  • reduce($data, $callback($value, $key), $initialValue);
    • Reduce's the given data with the given callback.
  • transform($data, $changes, $delimiter);
    • Transform the keys (change) of the given $data array with the $changes array. To navigate along the array, use the Laravel's dot syntax. If $delimiter provided, it changed the Laravel's dot syntax separator.
  • transformArray($data, $changed, $delimiter);
    • Same as transform, but should be used on a list, which will apply on every item. Same as map with transform.

Transformer class

Simple array transformer class, which convert all the keys by new ones. Something like a from-to where the all the keys of the given array will be replaced the by the value of the given replaced array when the key matches.

Example:

$transformer = new Transformer(['namae' => 'nombre']);
$data = ['namae' => 'William'];
$transformedData = $transformer->transform($data);

print_r($transformedData); // ['nombre' => 'William'];

Contributing

Feel free to make any pull request you judge necessary!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固