/vendor/fusonic/linq/src/Fusonic/Linq/Iterator/DistinctIterator.php |
@@ -0,0 +1,62 @@ |
<?php |
|
/* |
* This file is part of Fusonic-linq. |
* https://github.com/fusonic/fusonic-linq |
* |
* (c) Fusonic GmbH |
* |
* For the full copyright and license information, please view the LICENSE |
* file that was distributed with this source code. |
*/ |
|
namespace Fusonic\Linq\Iterator; |
|
use Iterator; |
|
class DistinctIterator extends \IteratorIterator |
{ |
private $iterator; |
private $distinct; |
|
public function __construct(Iterator $iterator) |
{ |
$this->iterator = $iterator; |
} |
|
public function current() |
{ |
return $this->distinct->current(); |
} |
|
public function next() |
{ |
$this->distinct->next(); |
} |
|
public function key() |
{ |
return $this->distinct->key(); |
} |
|
public function valid() |
{ |
return $this->distinct->valid(); |
} |
|
public function rewind() |
{ |
if ($this->distinct === null) { |
$this->getDistincts(); |
} |
|
$this->distinct->rewind(); |
} |
|
private function getDistincts() |
{ |
$data = iterator_to_array($this->iterator); |
$distinct = array_unique($data); |
$this->distinct = new \ArrayIterator($distinct); |
} |
} |
/vendor/fusonic/linq/src/Fusonic/Linq/Iterator/ExceptIterator.php |
@@ -0,0 +1,65 @@ |
<?php |
|
/* |
* This file is part of Fusonic-linq. |
* https://github.com/fusonic/fusonic-linq |
* |
* (c) Fusonic GmbH |
* |
* For the full copyright and license information, please view the LICENSE |
* file that was distributed with this source code. |
*/ |
|
namespace Fusonic\Linq\Iterator; |
|
use ArrayIterator; |
use Iterator; |
|
class ExceptIterator implements Iterator |
{ |
private $first; |
private $second; |
private $result; |
|
public function __construct(Iterator $first, Iterator $second) |
{ |
$this->first = $first; |
$this->second = $second; |
} |
|
public function current() |
{ |
return $this->result->current(); |
} |
|
public function next() |
{ |
$this->result->next(); |
} |
|
public function key() |
{ |
return $this->result->key(); |
} |
|
public function valid() |
{ |
return $this->result->valid(); |
} |
|
public function rewind() |
{ |
if ($this->result === null) { |
$this->getResult(); |
} |
|
$this->result->rewind(); |
} |
|
private function getResult() |
{ |
$firstArray = iterator_to_array($this->first); |
$secondArray = iterator_to_array($this->second); |
$this->result = new ArrayIterator(array_diff($firstArray, $secondArray)); |
} |
} |
/vendor/fusonic/linq/src/Fusonic/Linq/Iterator/GroupIterator.php |
@@ -0,0 +1,74 @@ |
<?php |
|
/* |
* This file is part of Fusonic-linq. |
* https://github.com/fusonic/fusonic-linq |
* |
* (c) Fusonic GmbH |
* |
* For the full copyright and license information, please view the LICENSE |
* file that was distributed with this source code. |
*/ |
|
namespace Fusonic\Linq\Iterator; |
|
use Iterator; |
use ArrayIterator; |
use Fusonic\Linq\GroupedLinq; |
|
class GroupIterator implements Iterator |
{ |
private $iterator; |
private $grouped; |
private $keySelector; |
|
public function __construct($iterator, $keySelector) |
{ |
$this->iterator = $iterator; |
$this->keySelector = $keySelector; |
} |
|
public function current() |
{ |
$current = $this->grouped->current(); |
return new GroupedLinq($current['key'], new \ArrayIterator($current['values'])); |
} |
|
public function next() |
{ |
$this->grouped->next(); |
} |
|
public function key() |
{ |
return $this->grouped->key(); |
} |
|
public function valid() |
{ |
return $this->grouped->valid(); |
} |
|
public function rewind() |
{ |
if ($this->grouped === null) { |
$this->doGroup(); |
} |
|
$this->grouped->rewind(); |
} |
|
private function doGroup() |
{ |
$keySelector = $this->keySelector; |
$this->grouped = new \ArrayIterator(array()); |
foreach ($this->iterator as $value) { |
$key = $keySelector($value); |
if (!isset($this->grouped[$key])) { |
$this->grouped[$key] = array('key' => $key, 'values'=> array()); |
} |
|
$this->grouped[$key]['values'][] = $value; |
} |
} |
} |
/vendor/fusonic/linq/src/Fusonic/Linq/Iterator/IntersectIterator.php |
@@ -0,0 +1,65 @@ |
<?php |
|
/* |
* This file is part of Fusonic-linq. |
* https://github.com/fusonic/fusonic-linq |
* |
* (c) Fusonic GmbH |
* |
* For the full copyright and license information, please view the LICENSE |
* file that was distributed with this source code. |
*/ |
|
namespace Fusonic\Linq\Iterator; |
|
use ArrayIterator; |
use Iterator; |
|
class IntersectIterator implements Iterator |
{ |
private $first; |
private $second; |
private $intersections; |
|
public function __construct(Iterator $first, Iterator $second) |
{ |
$this->first = $first; |
$this->second = $second; |
} |
|
public function current() |
{ |
return $this->intersections->current(); |
} |
|
public function next() |
{ |
$this->intersections->next(); |
} |
|
public function key() |
{ |
return $this->intersections->key(); |
} |
|
public function valid() |
{ |
return $this->intersections->valid(); |
} |
|
public function rewind() |
{ |
if ($this->intersections === null) { |
$this->calcIntersections(); |
} |
|
$this->intersections->rewind(); |
} |
|
private function calcIntersections() |
{ |
$firstArray = iterator_to_array($this->first); |
$secondArray = iterator_to_array($this->second); |
$this->intersections = new ArrayIterator(array_intersect($firstArray, $secondArray)); |
} |
} |
/vendor/fusonic/linq/src/Fusonic/Linq/Iterator/OfTypeIterator.php |
@@ -0,0 +1,94 @@ |
<?php |
/* |
* This file is part of Fusonic-linq. |
* https://github.com/fusonic/fusonic-linq |
* |
* (c) Burgy Benjamin <benjamin.burgy@gmail.com> |
* |
* For the full copyright and license information, please view the LICENSE |
* file that was distributed with this source code. |
*/ |
|
namespace Fusonic\Linq\Iterator; |
|
use FilterIterator; |
use Fusonic\Linq\Helper; |
use Iterator; |
|
/** |
* Iterator for filtering the Linq query with a specified <b>type</b>. |
* @package Fusonic\Linq\Iterator |
*/ |
final class OfTypeIterator |
extends |
\FilterIterator |
{ |
/** |
* @var callable $acceptCallback |
*/ |
private $acceptCallback; |
|
/** |
* Initializes an instance of <b>OfTypeIterator</b>. |
* |
* @param Iterator $iterator |
* @param string $type |
*/ |
public function __construct(Iterator $iterator, $type) |
{ |
parent::__construct($iterator); |
|
switch (strtolower($type)) |
{ |
case 'int': |
case 'integer': |
$this->acceptCallback = function ($current) |
{ |
return is_int($current); |
}; |
break; |
case 'float': |
case 'double': |
$this->acceptCallback = function ($current) |
{ |
return is_float($current); |
}; |
break; |
case 'string': |
$this->acceptCallback = function ($current) |
{ |
return is_string($current); |
}; |
break; |
case 'bool': |
case 'boolean': |
$this->acceptCallback = function ($current) |
{ |
return is_bool($current); |
}; |
break; |
|
default: |
$this->acceptCallback = function ($current) use ($type) |
{ |
return $current instanceof $type; |
}; |
} |
} |
|
/** |
* (PHP 5 >= 5.1.0)<br/> |
* Check whether the current element of the iterator is acceptable |
* @link http://php.net/manual/en/filteriterator.accept.php |
* @return bool true if the current element is acceptable, otherwise false. |
*/ |
public function accept() |
{ |
/** @var mixed $current */ |
$current = $this->current(); |
/** @var callable $func */ |
$func = $this->acceptCallback; |
|
return $func($current); |
} |
} |
/vendor/fusonic/linq/src/Fusonic/Linq/Iterator/OrderIterator.php |
@@ -0,0 +1,113 @@ |
<?php |
|
/* |
* This file is part of Fusonic-linq. |
* https://github.com/fusonic/fusonic-linq |
* |
* (c) Fusonic GmbH |
* |
* For the full copyright and license information, please view the LICENSE |
* file that was distributed with this source code. |
*/ |
|
namespace Fusonic\Linq\Iterator; |
|
use Iterator; |
use ArrayIterator; |
use Fusonic\Linq; |
use Fusonic\Linq\Helper; |
|
class OrderIterator implements Iterator |
{ |
private $iterator; |
private $direction; |
private $orderedIterator; |
private $orderKeyFunc; |
|
public function __construct(Iterator $items, $orderKeyFunc, $direction) |
{ |
$this->iterator = $items; |
$this->direction = $direction; |
$this->orderKeyFunc = $orderKeyFunc; |
} |
|
public function current() |
{ |
return $this->orderedIterator->current(); |
} |
|
public function next() |
{ |
$this->orderedIterator->next(); |
} |
|
public function key() |
{ |
return $this->orderedIterator->key(); |
} |
|
public function valid() |
{ |
return $this->orderedIterator->valid(); |
} |
|
public function rewind() |
{ |
if ($this->orderedIterator == null) { |
$this->orderItems(); |
} |
$this->orderedIterator->rewind(); |
} |
|
public function orderItems() |
{ |
$orderKeyFunc = $this->orderKeyFunc; |
$direction = $this->direction; |
|
$itemIterator = $this->iterator; |
$itemIterator->rewind(); |
if (!$itemIterator->valid()) { |
$this->orderedIterator = new ArrayIterator(); |
return; |
} |
|
$firstOrderKey = $orderKeyFunc($itemIterator->current()); |
|
$sortType = Helper\LinqHelper::LINQ_ORDER_TYPE_NUMERIC; |
|
if ($firstOrderKey instanceof \DateTime) { |
$sortType = Helper\LinqHelper::LINQ_ORDER_TYPE_DATETIME; |
} elseif (!is_numeric($firstOrderKey)) { |
$sortType = Helper\LinqHelper::LINQ_ORDER_TYPE_ALPHANUMERIC; |
} |
|
$keyMap = array(); |
$valueMap = array(); |
|
foreach ($itemIterator as $value) { |
$orderKey = $orderKeyFunc != null ? $orderKeyFunc($value) : $value; |
if ($sortType == Helper\LinqHelper::LINQ_ORDER_TYPE_DATETIME) { |
$orderKey = $orderKey->getTimeStamp(); |
} |
$keyMap[] = $orderKey; |
$valueMap[] = $value; |
} |
|
if ($sortType == Helper\LinqHelper::LINQ_ORDER_TYPE_DATETIME) { |
$sortType = Helper\LinqHelper::LINQ_ORDER_TYPE_NUMERIC; |
} |
|
if ($direction == Helper\LinqHelper::LINQ_ORDER_ASC) { |
asort($keyMap, $sortType == Helper\LinqHelper::LINQ_ORDER_TYPE_NUMERIC ? SORT_NUMERIC : SORT_LOCALE_STRING); |
} else { |
arsort($keyMap, $sortType == Helper\LinqHelper::LINQ_ORDER_TYPE_NUMERIC ? SORT_NUMERIC : SORT_LOCALE_STRING); |
} |
|
$sorted = new ArrayIterator(array()); |
foreach ($keyMap as $key => $value) { |
$sorted[] = $valueMap[$key]; |
} |
|
$this->orderedIterator = $sorted; |
} |
} |
/vendor/fusonic/linq/src/Fusonic/Linq/Iterator/SelectIterator.php |
@@ -0,0 +1,37 @@ |
<?php |
|
/* |
* This file is part of Fusonic-linq. |
* https://github.com/fusonic/fusonic-linq |
* |
* (c) Fusonic GmbH |
* |
* For the full copyright and license information, please view the LICENSE |
* file that was distributed with this source code. |
*/ |
|
namespace Fusonic\Linq\Iterator; |
|
use InvalidArgumentException; |
use Iterator; |
|
class SelectIterator extends \IteratorIterator |
{ |
private $selector; |
|
public function __construct(Iterator $iterator, $selector) |
{ |
parent::__construct($iterator); |
if ($selector === null) { |
throw new InvalidArgumentException("Selector must not be null."); |
} |
|
$this->selector = $selector; |
} |
|
public function current() |
{ |
$selector = $this->selector; |
return $selector(parent::current()); |
} |
} |
/vendor/fusonic/linq/src/Fusonic/Linq/Iterator/SelectManyIterator.php |
@@ -0,0 +1,84 @@ |
<?php |
|
/* |
* This file is part of Fusonic-linq. |
* https://github.com/fusonic/fusonic-linq |
* |
* (c) Fusonic GmbH |
* |
* For the full copyright and license information, please view the LICENSE |
* file that was distributed with this source code. |
*/ |
|
namespace Fusonic\Linq\Iterator; |
|
use Iterator; |
use Fusonic\Linq\Helper; |
|
class SelectManyIterator implements Iterator |
{ |
private $iterator; |
private $currentIterator; |
private $key = 0; |
|
public function __construct(Iterator $iterator) |
{ |
$this->iterator = $iterator; |
} |
|
public function current() |
{ |
if ($this->currentIterator != null) { |
return $this->currentIterator->current(); |
} |
|
return null; |
} |
|
public function next() |
{ |
if ($this->currentIterator != null) { |
$this->currentIterator->next(); |
|
if (!$this->currentIterator->valid()) { |
$this->iterator->next(); |
if ($this->iterator->valid()) { |
$this->currentIterator = Helper\LinqHelper::getIteratorOrThrow($this->iterator->current()); |
if ($this->currentIterator != null) { |
$this->currentIterator->rewind(); |
$this->key++; |
} |
} |
} else { |
$this->key++; |
} |
} |
} |
|
public function key() |
{ |
return $this->key; |
} |
|
public function valid() |
{ |
$current = $this->currentIterator; |
return $current != null && $current->valid(); |
} |
|
public function rewind() |
{ |
$this->iterator->rewind(); |
if ($this->iterator->valid()) { |
$current = $this->iterator->current(); |
$this->currentIterator = Helper\LinqHelper::getIteratorOrThrow($current); |
if ($this->currentIterator != null) { |
$this->currentIterator->rewind(); |
} |
} else { |
$this->currentIterator = null; |
} |
|
$this->key = 0; |
} |
} |
/vendor/fusonic/linq/src/Fusonic/Linq/Iterator/WhereIterator.php |
@@ -0,0 +1,34 @@ |
<?php |
|
/* |
* This file is part of Fusonic-linq. |
* https://github.com/fusonic/fusonic-linq |
* |
* (c) Fusonic GmbH |
* |
* For the full copyright and license information, please view the LICENSE |
* file that was distributed with this source code. |
*/ |
|
namespace Fusonic\Linq\Iterator; |
|
use Iterator; |
use Fusonic\Linq\Helper; |
|
class WhereIterator extends \FilterIterator |
{ |
private $func; |
|
public function __construct(Iterator $iterator, $func) |
{ |
parent::__construct($iterator); |
$this->func = $func; |
} |
|
public function accept() |
{ |
$func = $this->func; |
$current = $this->current(); |
return Helper\LinqHelper::getBoolOrThrowException($func($current)); |
} |
} |