2017 © Pedro Peláez
 

library collection

Object Orientated implementations of various collections

image

bolt/collection

Object Orientated implementations of various collections

  • Tuesday, November 28, 2017
  • by bobdenotter
  • Repository
  • 7 Watchers
  • 8 Stars
  • 32,130 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 14 % Grown

The README.md

Bolt Collection

travis codecov, (*1)

This library provides objects and functionality to help with groups of items and data sets., (*2)

Check out the API documentation., (*3)

Bag and MutableBag

These are object-oriented implementations of arrays., (*4)

The goal of these classes: - Provide functionality on par with built-in array methods - Provide useful functionality lacking from built-in array methods - Provide a fluent-like experience - Make implementing code more readable, (*5)

Examples

$arr = [
    'debug' => true,
    'color' => 'blue',
    'db' => [
        'driver' => 'sqlite',
    ],
];

$bag = Bag::from($arr)
    ->defaults([
        'debug' => false,
        'color' => 'green',
    ])
    ->replace([
        'color' => 'red',
    ])
;
$bag->get('debug'); // true
$bag->getPath('db/driver'); // "sqlite"
$bag->keys()->join(', '); // "debug, color, db"
$bag->isAssociative(); // true
$colors = MutableBag::of('red', 'blue', 'yellow')
    ->merge(['green', 'orange'])
;
$colors->isIndexed(); // true
$colors->indexOf('yellow'); // 2
$colors[2]; // "yellow"

$colors->prepend('purple');
$colors[] = 'pink';

$colors->first(); // "purple"
$colors->last(); // "pink"

$colors->shuffle()->first(); // one of the colors

$colors->chunk(2); // Bags represented as arrays:
// [ ['purple', 'red'], ['blue', 'yellow'], ['green, 'orange'], ['pink'] ]

$colors->removeFirst(); // "purple"
$colors->removeFirst(); // "red"

These examples only cover half of the functionality. See the API documentation for more., (*6)

All methods accepting a collection will accept other Bags, arrays, stdClass, and Traversable objects. This makes it very easy work with any collection-like object., (*7)

Hasn't this been done already?

Obviously others think PHP arrays suck as well and have attempted to resolve this., (*8)

Symfony's ParameterBag is a good basic _map_ (associative arrays) container but is lacking when it comes to mutating the items around and working with lists., (*9)

Doctrine's ArrayCollection is also another, more robust, option. It works well for maps and lists, but still has limited functionality due to needing to interface with a database collection. It also has some annoyances, like getKeys() returns an array instead of another ArrayCollection instance., (*10)

The Versions

28/11 2017
21/11 2017

dev-next

dev-next

Object Orientated implementations of various collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carson Full

16/11 2017

dev-native-function-invocation

dev-native-function-invocation

Object Orientated implementations of various collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carson Full

05/08 2017

1.0.x-dev

1.0.9999999.9999999-dev

Object Orientated implementations of various collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carson Full

15/06 2017

dev-feature/arr-from

dev-feature/arr-from

Object Orientated implementations of various collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carson Full

27/05 2017

1.0.0

1.0.0.0

Object Orientated implementations of various collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carson Full

27/05 2017

v1.0.0

1.0.0.0

Object Orientated implementations of various collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carson Full

14/04 2017

dev-codeclimate

dev-codeclimate

Object Orientated implementations of various collections

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carson Full