phf / collection
Collections utility class
Installs: 150
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/phf/collection
Requires
- php: >=7
- phf/varinfo: ^1
Requires (Dev)
This package is auto-updated.
Last update: 2025-10-06 04:21:17 UTC
README
DRY helper for collections of validated elements.
With type hinted properties they can ensure type safety on collections without setters.
class Foo { public StringCollection $bar; public function __construct() { $this->bar = new StringCollection(); } } $foo = new Foo(); $foo->bar[] = 123; // throws InvalidArgumentException
Extend for own entities:
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(); } }