2017 © Pedro PelĂĄez
 

library typed-collections

A simple way to create typed collections in PHP - build on Illuminate\Support\Collection

image

phpsafari/typed-collections

A simple way to create typed collections in PHP - build on Illuminate\Support\Collection

  • Thursday, August 17, 2017
  • by vistik
  • Repository
  • 1 Watchers
  • 3 Stars
  • 42 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 4 Versions
  • 320 % Grown

The README.md

Build Status, (*1)

What is this?

This is a very simple way to make arrays type hinted!, (*2)

$list = new UserCollection(new User());, (*3)

OK, (*4)

$list = new UserCollection('User');, (*5)

Will throw:, (*6)

Vistik\Exception\InvalidTypeException: Item (string) 'User' is not a Vistik\Example\User object!, (*7)

Install

Run composer require vistik/typed-collections, (*8)

Use build in Collections for primitives

Out-of-the-box collections for: - Booleans - Integers - Floats - Strings - Emails - Numbers (float or int), (*9)

They can be created with out-of-the-box laraval style helpers:, (*10)

  • bCollect([true, false]) - To create a BoolCollection
  • iCollect([1, 2, 3, 4]) - To create a IntegerCollection
  • fCollect([3.14, 22/7, 6.66]) - To create a FloatCollection
  • sCollect(['hello', 'world'']) - To create a StringCollection
  • eCollect(['hello@example.org', 'write@me.com']) - To create a EmailCollection
  • nCollect([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:, (*11)

use Phpsafari\Example\User;
class UserCollection extends TypedCollection{
    protected $type = User::class;
}

2 simple steps, (*12)

1) Create a Class eg. AccountCollection extend TypedCollection
2) Just replace protected $type = 'Vistik\Example\User'; with your class, (*13)

or, (*14)

If the check is more then just a is_a check, you can overwrite the function: isValidItem($item) in your new Collection class, (*15)

Features

The Versions

17/08 2017

dev-master

9999999-dev

A simple way to create typed collections in PHP - build on Illuminate\Support\Collection

  Sources   Download

MIT

The Requires

 

The Development Requires

by Visti Kløft

collection array collections type hint type hinted

28/07 2017

v2.0.2

2.0.2.0

A simple way to create typed collections in PHP - build on Illuminate\Support\Collection

  Sources   Download

MIT

The Requires

 

The Development Requires

by Visti Kløft

collection array collections type hint type hinted

18/02 2017

v2.0.1

2.0.1.0

A simple way to create typed collections in PHP - build on Illuminate\Support\Collection

  Sources   Download

MIT

The Requires

 

The Development Requires

by Visti Kløft

collection array collections type hint type hinted

12/02 2017

v2.0.0

2.0.0.0

A simple way to create typed collections in PHP - build on Illuminate\Support\Collection

  Sources   Download

The Requires

 

The Development Requires

by Visti Kløft

collection array collections type hint type hinted