2017 © Pedro Peláez
 

library pipe-array

improve PHP array manipulation by Collection Pipeline pattern

image

aznc/pipe-array

improve PHP array manipulation by Collection Pipeline pattern

  • Thursday, July 2, 2015
  • by weiclin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

PipeArray

the PipeArray provide a way to manipulate array by Collection Pipeline pattern. although PHP has provide many array_* functions, they are a little annoying to combined together:, (*1)

$score = [40, 55, 32, 63];

// add bonus and check passed score
$bonusScore = array_map(function($e){ return intval(sqrt($e) * 10); }, $score);
$passedScore = array_filter($bonusScore, function($e){ return $e >= 60; });

use the Collection Pipeline pattern are more clear:, (*2)

$score = [40, 55, 32, 63];

// add bonus and check passed score
$passedScore = Pipe::Start($score)
                ->map(function($e){ return intval(sqrt($e) * 10); })
                ->filter(function($e){ return $e >= 60; })
                ->rawData();

Pipe::Start() return a instance of PipeArray which can used as normal array as well as by OO way:, (*3)

$pArray = Pipe::Start([1, 2, 3, 4, 5]);
$pArray->push(6);
var_dump($pArray[5]); // print 6

$pArray->pop();
var_dump($pArray->count()); // print 5

the PipeArray can use like an array, but it's exactly an object. some array function require real PHP array, you can retrieve it by calling rawData() method:, (*4)

$phpArray = Pipe::Start(...)->map(...)->rawData();

Most array_* functions are available in the PipeArray class, except: - that didn't generate result from current array, like array_fill - that require another array as parameter, like array_diff, (*5)

also the function name has a little change: - the "array_" part are removed, for example, array_key_exists equals to PipeArray->key_exists() - it provide camel case method, for example, key_exists() is an aliases for keyExists(), (*6)

Install

By Composer:, (*7)

  "require": {
    "aznc/pipe-array": "^1.0.0"
  }

The Versions

02/07 2015

dev-master

9999999-dev

improve PHP array manipulation by Collection Pipeline pattern

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Wei-Chen Lin

02/07 2015

1.0.0

1.0.0.0

improve PHP array manipulation by Collection Pipeline pattern

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Wei-Chen Lin