typed collections
v2.0.2
これは、配列の型ヒントを作成する非常に簡単な方法です。
$list = new UserCollection(new User());
わかりました
$list = new UserCollection('User');
スローします:
VistikExceptionInvalidTypeException: Item (string) 'User' is not a VistikExampleUser object!
composer require vistik/typed-collections
すぐに使えるコレクション:
これらは、すぐに使える laraval スタイル ヘルパーを使用して作成できます。
bCollect([true, false]) - BoolCollection を作成するにはiCollect([1, 2, 3, 4]) - IntegerCollection を作成するにはfCollect([3.14, 22/7, 6.66]) - FloatCollection を作成するにはsCollect(['hello', 'world'']) - StringCollection を作成するにはeCollect(['[email protected]', '[email protected]']) - EmailCollection を作成するにはnCollect([1, 2, 3, 4, 3.14, INF]) - NumberCollection を作成するにはとても簡単です:
use PhpsafariExampleUser;
class UserCollection extends TypedCollection{
protected $type = User::class;
}
2つの簡単なステップ
AccountCollection TypedCollectionを拡張しますprotected $type = 'VistikExampleUser';あなたのクラスと一緒にまたは
チェックが単なるis_aチェック以上の場合は、新しい Collection クラスの関数isValidItem($item)を上書きできます。