vistik/type-hinted-arrays
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/type-hinted-arrays
Use build in Collections for primitives
Out-of-the-box collections for:
- Booleans
- Integers
- Floats
- Strings
- Emails
- Numbers (float or int)
Do I have to create a type for each list? Yes, but
Look how easy it is:
class UserCollection extends TypedCollection{
protected $type = 'Vistik\Example\User';
}
2 simple steps
- Create a Class eg.
AccountCollectionextendTypedCollection - 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
Related Packages
A collection library inspired by Laravel Collections, built using generators to...
Laravel-compatible PHP collection with dot-notation and wildcard paths in every...
This package provides type-safe extension of the laravel collection, forcing a s...
A thin wrapper around Illuminate/Collection that allows for enforcing type const...
Easy and elegant handling of PHP arrays as array-like collection objects similar...
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v2.0.0 | >=7.0.0 | ~5.4 | ||
| v1.0.3 | >=5.3.0 | ~5.0 | ||
| v1.0.2 | >=5.3.0 | ~5.0 | ||
| v1.0.1 | >=5.3.0 | ~5.0 | ||
| v1.0.0 | >=5.3.0 | ~5.0 |