2017 © Pedro Peláez
 

library collection

Eden generic collection component

image

eden/collection

Eden generic collection component

  • Friday, November 13, 2015
  • by cblanquera
  • Repository
  • 14 Watchers
  • 0 Stars
  • 10,339 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 2 % Grown

The README.md

logo Eden Collection

Build Status

====, (*1)

, (*2)

Install

composer install eden/collection, (*3)

====, (*4)

, (*5)

Introduction

Manipulating table, matrix or multidimensional data in most cases can be expressed as a collection. Collections in Eden is defined loosely and as a utility class to help managing data in a controlled and chainable format. The basic setup of a collection is described in Figure 1., (*6)

Figure 1. Setup, (*7)

$users = array(
    array(
        'user_name' => 'Chris',
        'user_email' => 'cblanquera@openovate.com',
        'user_location' => 'Manila, Philippines'
    ),

    array(
        'user_name' => 'Dan',
        'user_email' => 'dmolina@openovate.com',
        'user_location' => 'Manila, Philippines'
    ),
);

eden('collection', $users);, (*8)

Collections do exactly the same thing as models except it manipulates multiple models instead. Collections can be iterable and access as arrays as well. Collections only hold model objects so if you wanted to use your own extended model, you would need to call ->setModel('Your_Model'). From here we can access properties in our collection as a method, property or back as an array. Figure 2 shows the ways to access data in action., (*9)

**Figure 2. Accessing Collection, Models and Rows **, (*10)

//set user name for all rows
$collection->setUserName('Chris');

// set or get any abstract key for all rows
$collection->setAnyThing();

//collections are iterable
foreach($collection as $model) {        
    echo $model->getUserName().' ';
    echo $model['user_email'];
}

//access as array
echo $collection[0]['user_name'];
//set as array
$collection[0]['user_email'] = 'my@email.com'; 

Some other utility methods not covered by th above examples are date formating and copying from one column to another. Figure 3, show how we would go about doing these things., (*11)

Figure 3. Utility methods, (*12)

//for each row, copy the value of post_user to the user_id column
$collection->copy('post_user', 'user_id');

//remove the row with the index of 1, reindexes all the rows
$collection->cut(1);

//returns the number of rows
$collection->count();

//adds a new row
$collection->add(array('post_title' => 'Hi'));

//returns a table array (no objects)
$collection->get();   

====, (*13)

, (*14)

Contributing to Eden

Contributions to Eden are following the Github work flow. Please read up before contributing., (*15)

Setting up your machine with the Eden repository and your fork

  1. Fork the repository
  2. Fire up your local terminal create a new branch from the v4 branch of your fork with a branch name describing what your changes are. Possible branch name types:
    • bugfix
    • feature
    • improvement
  3. Make your changes. Always make sure to sign-off (-s) on all commits made (git commit -s -m "Commit message")

Making pull requests

  1. Please ensure to run phpunit before making a pull request.
  2. Push your code to your remote forked version.
  3. Go back to your forked version on GitHub and submit a pull request.
  4. An Eden developer will review your code and merge it in when it has been classified as suitable.

The Versions

13/11 2015

4.x-dev

4.9999999.9999999.9999999-dev http://eden-php.com

Eden generic collection component

  Sources   Download

MIT

The Requires

 

by Christian Blanquera

library eden

13/10 2015

dev-master

9999999-dev http://eden-php.com

Eden generic collection component

  Sources   Download

MIT

The Requires

 

by Christian Blanquera

library eden

13/10 2015

4.0.1

4.0.1.0 http://eden-php.com

Eden generic collection component

  Sources   Download

MIT

The Requires

 

by Christian Blanquera

library eden

08/10 2015

4.0.0

4.0.0.0 http://eden-php.com

Eden generic collection component

  Sources   Download

MIT

The Requires

 

by Christian Blanquera

library eden

24/09 2013

1.0.3

1.0.3.0 http://eden-php.com

Eden generic collection component

  Sources   Download

MIT

The Requires

 

by Christian Blanquera

library eden

24/09 2013

1.0.2

1.0.2.0 http://eden-php.com

Eden generic collection component

  Sources   Download

MIT

The Requires

 

by Christian Blanquera

library eden