Things you must note
     - Plinq depends on knowledge of "closures", you can view a brief description about closures from the link: About Closures
     - You must have at least PHP 5.3.1

Usage

  - Closure policy: The closures you created must always accept two parameters, which the first parameter is the key of item and the second is the value;

 function($itemKey,$itemValue){ return $itemValue; }

  - Creating a Plinq object: A Plinq object is actually derived from SPL Object "RecursiveArrayIterator". So it has all the thing that an ordinary array has, plus, it makes querying the items via closures;   

//assume that users is an array of "User" object
$users = $userRepository->GetAllUsers();
        
//create the object
$plinq = new Plinq($users);
        
//gets the users that are older than 60
$oldies = $plinq->Where(function($k, $v){ return $v->Age > 60; });


  - Chaining: Plinq is fully chainable, all methods returns a Plinq object;

$plinq->Where(...)->Skip(4)->Take(33)->Select(...);

  - Methods
    1) [Plinq::Where]

//get members older than 30
$result = $plinq->Where(function($k, $v){ return ($v->age > 30); });
        
var_dump($result);
/*
object(Library\Plinq\Plinq)#16 (1) {
  ["storage":"ArrayIterator":private]=>
  array(1) {
    [0]=>
    object(Domain\Model\Member)#6 (4) {
      ["Id"]=>
      int(245)
      ["email"]=>
      string(13) "plinq@member1"
      ["isActive"]=>
      bool(true)
      ["age"]=>
      int(47)
    }
  }
}

*/

    2) [Plinq::Skip]
    3) [Plinq::All]
    4) [Plinq::Any]
    5) [Plinq::Average]
    6) [Plinq::OrderBy]
    7) [Plinq::OrderByDescending]
    8) [Plinq::Max]
    9) [Plinq::Min]
    10) [Plinq::Select]
    11) [Plinq::SelectMany]
    12) [Plinq::Concat]
    13) [Plinq::Distinct]
    14) [Plinq::Intersect]
    15) [Plinq::Diff]
    16) [Plinq::ElementAt]
    17) [Plinq::GroupBy]
    18) [Plinq::First]
    19) [Plinq::Last]
    20) [Plinq::Single]
    21) [Plinq::Take]
    22) [Plinq::ToArray]

Last edited Mar 29, 2011 at 10:50 PM by mowa, version 12

Comments

Eldarado Mar 12, 2015 at 12:31 PM 
When well be all documantation?

akumarmca May 25, 2011 at 9:22 AM 
Plinq class is very helpful for operate above methods in short coding.