bittyphp / collection
Simple collections.
Installs: 26 649
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.1.0
Requires (Dev)
- codacy/coverage: ^1.4
- jakub-onderka/php-parallel-lint: ^1.0
- localheinz/composer-normalize: ^1.1
- phing/phing: ^2.16
- phpstan/phpstan: ^0.10.7
- phpstan/phpstan-deprecation-rules: ^0.10.2
- phpstan/phpstan-phpunit: ^0.10.0
- phpstan/phpstan-strict-rules: ^0.10.1
- phpunit/phpunit: ^7.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2023-01-10 16:03:23 UTC
README
Simple object collections.
Installation
It's best to install using Composer.
$ composer require bittyphp/collection
Readable Collections
Readable collections MUST implement Bitty\Collection\ReadableCollectionInterface
. The interface only offers the very basic methods: has()
, get()
, and all()
.
Basic Usage
<?php use Bitty\Collection\ReadableArrayCollection; $collection = new ReadableArrayCollection( [ 'foo' => 'bar', 'baz' => ['blar', 'blah', 'blam'], ] ); // Check if data exists. if ($collection->has('foo')) { // Do something. } // Get data, or get a default value if it doesn't exist. $default = 'not set'; $value = $collection->get('foo', $default); // Get all the data. $data = $collection->all();
Writable Collections
Writable collections MUST implement Bitty\Collection\WritableCollectionInterface
. The interface extends Bitty\Collection\ReadableCollectionInterface
and adds an additional set()
.
Basic Usage
<?php use Bitty\Collection\WritableArrayCollection; $collection = new WritableArrayCollection( [ 'foo' => 'bar', 'baz' => ['blar', 'blah', 'blam'], ] ); // Add new data to the collection. $collection->set('key', 'value');
Removable Collections
Removable collections MUST implement Bitty\Collection\RemovableCollectionInterface
. The interface extends Bitty\Collection\WritableCollectionInterface
and adds an additional remove()
and clear()
.
Basic Usage
<?php use Bitty\Collection\RemovableArrayCollection; $collection = new RemovableArrayCollection( [ 'foo' => 'bar', 'baz' => ['blar', 'blah', 'blam'], ] ); // Remove one item. $collection->remove('foo'); // Clear all the data. $collection->clear();