Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ph-fritsche/php-collection
https://github.com/ph-fritsche/php-collection
Last synced: 24 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ph-fritsche/php-collection
- Owner: ph-fritsche
- License: mit
- Created: 2021-05-05T12:20:13.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-05-05T18:25:39.000Z (over 3 years ago)
- Last Synced: 2024-05-04T12:02:39.659Z (6 months ago)
- Language: PHP
- Size: 35.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Collection
DRY helper for collections of validated elements.
With type hinted properties they can ensure type safety on collections without setters.
```php
class Foo
{
public StringCollection $bar;public function __construct()
{
$this->bar = new StringCollection();
}
}$foo = new Foo();
$foo->bar[] = 123; // throws InvalidArgumentException
```Extend for own entities:
```php
class BarEntity
{
public string $baz;
}class BarCollection extends \PhF\Collection\Collection
{
protected static $invalidElementMessageAllowed = BarEntity::class;public function validate(
$value
): bool {
return $value instanceof BarEntity;
}
}class Foo
{
public BarCollection $bar;public function __construct()
{
$this->bar = new BarCollection();
}
}
```