fiv/collection

Easy way to iterate over your data

0.0.1 2014-11-07 10:26 UTC

This package is auto-updated.

Last update: 2024-11-12 07:10:22 UTC


README

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

Manipulate array of items in OOP style. ObjectCollection - contain/manipulate objects only with specific class TypedCollection - contain/manipulate items with defined validation rule BaseCollection - contain/manipulate any items

ObjectCollection it the most useful collection. You can specify class of object and add only this objects. All validations perform ObjectCollection Other data types restricted. This class guarantee strict type data.

Install

Via Composer

$ composer require fiv/collection

Base collection usage

$collection = new \Fiv\Collection\BaseCollection();
$collection[] = 1;
$collection[] = 2;
echo $skeleton->getFirst()

Example : ObjectCollection

In java there ara features like ArrayList<UserModel> in php you can extend ObjectCollection to UserModelCollection and define class name.

class UserModel {
  public function getName(){
  
  }
}

class UsersCollection extend  ObjectCollection {
  public function objectsClassName(){
    return 'UserModel';
  }
}

# .... 
$users = new UserCollection();

foreach($users as $user){
  # at this point you can drop out all you validations
  # ObjectCollection guarantee that all items are UserModel
  $user->getName(); 
}


$users->append(123); // Fail. 123 is not instance of UserModel  

Testing

$ ./vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.