Download the PHP package vistik/typed-collections without Composer
On this page you can find all versions of the php package vistik/typed-collections. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vistik/typed-collections
More information about vistik/typed-collections
Files in vistik/typed-collections
Package typed-collections
Short Description A simple way to create typed collections in PHP - build on Illuminate\Support\Collection
License MIT
Informations about the package typed-collections
What is this?
This is a very simple way to make arrays type hinted!
$list = new UserCollection(new User());
OK
$list = new UserCollection('User');
Will throw:
Vistik\Exception\InvalidTypeException: Item (string) 'User' is not a Vistik\Example\User object!
Install
Run composer require vistik/typed-collections
Use build in Collections for primitives
Out-of-the-box collections for:
- Booleans
- Integers
- Floats
- Strings
- Emails
- Numbers (float or int)
They can be created with out-of-the-box laraval style helpers:
bCollect([true, false])
- To create a BoolCollectioniCollect([1, 2, 3, 4])
- To create a IntegerCollectionfCollect([3.14, 22/7, 6.66])
- To create a FloatCollectionsCollect(['hello', 'world''])
- To create a StringCollectioneCollect(['[email protected]', '[email protected]'])
- To create a EmailCollectionnCollect([1, 2, 3, 4, 3.14, INF])
- To create a NumberCollection
Do I have to create a type for each list? Yes, but
Look how easy it is:
use Phpsafari\Example\User;
class UserCollection extends TypedCollection{
protected $type = User::class;
}
2 simple steps
1) Create a Class eg. AccountCollection
extend TypedCollection
2) Just replace protected $type = 'Vistik\Example\User';
with your class
or
If the check is more then just a is_a
check, you can overwrite the function: isValidItem($item)
in your new Collection class
Features
- Build upon Illuminate\Support\Collection
- Very simple to implement custom Collections
All versions of typed-collections with dependencies
illuminate/support Version 5.4.*|5.3.*|5.2.*|5.1.*
squizlabs/php_codesniffer Version *