uawdijnntqw1x1x1
IP : 216.73.216.136
Hostname : dhandapanilive
Kernel : Linux dhandapanilive 5.15.0-139-generic #149~20.04.1-Ubuntu SMP Wed Apr 16 08:29:56 UTC 2025 x86_64
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
OS : Linux
PATH:
/
var
/
www
/
html
/
dhandapani
/
968c0
/
..
/
generated
/
..
/
9da53
/
phpcollection.tar
/
/
phpcollection/src/PhpCollection/ObjectBasicsHandlerRegistry.php000077700000005353151323647100021053 0ustar00<?php namespace PhpCollection; use PhpCollection\ObjectBasicsHandler\IdentityHandler; /** * Registry for handlers that provide ObjectBasics functionality for classes. * * You want to register a handler if you cannot implement the ObjectBasics interface, for example * because a class is provided by a third-party package, or built into PHP. * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ abstract class ObjectBasicsHandlerRegistry { private static $handlers = array( 'DateTime' => 'PhpCollection\\ObjectBasicsHandler\\DateTimeHandler', ); private static $defaultObjectHandler; private static $aliases = array(); /** * Defines an alias. * * $aliasClass must be a sub-type (extend or implement) $handlingClass; otherwise you will run into trouble. * * Aliases can only be one level deep, * * i.e. aliasClass -> handlingClass is supported, * but aliasClass -> anotherAliasClass -> handlingClass is not. * * @param string $handlingClass The class that should be aliased, i.e. MyDateTime * @param string $aliasClass The class that should be used instead, i.e. DateTime */ public static function addAliasFor($handlingClass, $aliasClass) { self::$aliases[$handlingClass] = $aliasClass; } public static function addHandlerFor($handlingClass, $handlerInstanceOrClassName) { if ( ! $handlerInstanceOrClassName instanceof ObjectBasicsHandler && ! is_string($handlerInstanceOrClassName)) { throw new \LogicException('$handler must be an instance of ObjectBasicsHandler, or a string referring to the handlers class.'); } self::$handlers[$handlingClass] = $handlerInstanceOrClassName; } public static function getHandler($className) { if (isset(self::$aliases[$className])) { $className = self::$aliases[$className]; } if ( ! isset(self::$handlers[$className])) { if (self::$defaultObjectHandler === null) { self::$defaultObjectHandler = new IdentityHandler(); } return self::$defaultObjectHandler; } if (self::$handlers[$className] instanceof ObjectBasicsHandler) { return self::$handlers[$className]; } if (is_string(self::$handlers[$className])) { $handlerClass = self::$handlers[$className]; return self::$handlers[$className] = new $handlerClass(); } throw new \LogicException(sprintf( 'Unknown handler type ("%s") for class "%s" - should never be reached.', gettype(self::$handlers[$className]), $className )); } private final function __construct() { } }phpcollection/src/PhpCollection/AbstractSequence.php000077700000021576151323647100016732 0ustar00<?php /* * Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace PhpCollection; use PhpOption\Some; use PhpOption\None; use PhpOption\Option; use OutOfBoundsException; /** * A sequence with numerically indexed elements. * * This is rawly equivalent to an array with only numeric keys. * There are no restrictions on how many same values may occur in the sequence. * * This sequence is mutable. * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ class AbstractSequence extends AbstractCollection implements \IteratorAggregate, SequenceInterface { protected $elements; /** * @param array $elements */ public function __construct(array $elements = array()) { $this->elements = array_values($elements); } public function addSequence(SequenceInterface $seq) { $this->addAll($seq->all()); } public function indexOf($searchedElement) { foreach ($this->elements as $i => $element) { if ($searchedElement === $element) { return $i; } } return -1; } public function lastIndexOf($searchedElement) { for ($i=count($this->elements)-1; $i>=0; $i--) { if ($this->elements[$i] === $searchedElement) { return $i; } } return -1; } public function reverse() { return $this->createNew(array_reverse($this->elements)); } public function isDefinedAt($index) { return isset($this->elements[$index]); } /** * Returns a filtered sequence. * * @param callable $callable receives the element and must return true (= keep) or false (= remove). * * @return AbstractSequence */ public function filter($callable) { return $this->filterInternal($callable, true); } public function map($callable) { $newElements = array(); foreach ($this->elements as $i => $element) { $newElements[$i] = $callable($element); } return $this->createNew($newElements); } /** * Returns a filtered sequence. * * @param callable $callable receives the element and must return true (= remove) or false (= keep). * * @return AbstractSequence */ public function filterNot($callable) { return $this->filterInternal($callable, false); } private function filterInternal($callable, $booleanKeep) { $newElements = array(); foreach ($this->elements as $element) { if ($booleanKeep !== call_user_func($callable, $element)) { continue; } $newElements[] = $element; } return $this->createNew($newElements); } public function foldLeft($initialValue, $callable) { $value = $initialValue; foreach ($this->elements as $elem) { $value = call_user_func($callable, $value, $elem); } return $value; } public function foldRight($initialValue, $callable) { $value = $initialValue; foreach (array_reverse($this->elements) as $elem) { $value = call_user_func($callable, $elem, $value); } return $value; } /** * Finds the first index where the given callable returns true. * * @param callable $callable * * @return integer the index, or -1 if the predicate is not true for any element. */ public function indexWhere($callable) { foreach ($this->elements as $i => $element) { if (call_user_func($callable, $element) === true) { return $i; } } return -1; } public function lastIndexWhere($callable) { for ($i=count($this->elements)-1; $i>=0; $i--) { if (call_user_func($callable, $this->elements[$i]) === true) { return $i; } } return -1; } public function last() { if (empty($this->elements)) { return None::create(); } return new Some(end($this->elements)); } public function first() { if (empty($this->elements)) { return None::create(); } return new Some(reset($this->elements)); } public function indices() { return array_keys($this->elements); } /** * Returns an element based on its index (0-based). * * @param integer $index * * @return T */ public function get($index) { if ( ! isset($this->elements[$index])) { throw new OutOfBoundsException(sprintf('The index "%s" does not exist in this sequence.', $index)); } return $this->elements[$index]; } /** * Removes the element at the given index, and returns it. * * @param int $index * * @return T * * @throws \OutOfBoundsException If there is no element at the given index. */ public function remove($index) { if ( ! isset($this->elements[$index])) { throw new OutOfBoundsException(sprintf('The index "%d" is not in the interval [0, %d).', $index, count($this->elements))); } $element = $this->elements[$index]; unset($this->elements[$index]); $this->elements = array_values($this->elements); return $element; } /** * Updates the element at the given index (0-based). * * @param integer $index * @param T $value */ public function update($index, $value) { if ( ! isset($this->elements[$index])) { throw new \InvalidArgumentException(sprintf('There is no element at index "%d".', $index)); } $this->elements[$index] = $value; } public function isEmpty() { return empty($this->elements); } public function all() { return $this->elements; } public function add($newElement) { $this->elements[] = $newElement; } public function addAll(array $addedElements) { foreach ($addedElements as $newElement) { $this->elements[] = $newElement; } } public function take($number) { if ($number <= 0) { throw new \InvalidArgumentException(sprintf('$number must be greater than 0, but got %d.', $number)); } return $this->createNew(array_slice($this->elements, 0, $number)); } /** * Extracts element from the head while the passed callable returns true. * * @param callable $callable receives elements of this sequence as first argument, and returns true/false. * * @return Sequence */ public function takeWhile($callable) { $newElements = array(); for ($i=0,$c=count($this->elements); $i<$c; $i++) { if (call_user_func($callable, $this->elements[$i]) !== true) { break; } $newElements[] = $this->elements[$i]; } return $this->createNew($newElements); } public function drop($number) { if ($number <= 0) { throw new \InvalidArgumentException(sprintf('The number must be greater than 0, but got %d.', $number)); } return $this->createNew(array_slice($this->elements, $number)); } public function dropRight($number) { if ($number <= 0) { throw new \InvalidArgumentException(sprintf('The number must be greater than 0, but got %d.', $number)); } return $this->createNew(array_slice($this->elements, 0, -1 * $number)); } public function dropWhile($callable) { for ($i=0,$c=count($this->elements); $i<$c; $i++) { if (true !== call_user_func($callable, $this->elements[$i])) { break; } } return $this->createNew(array_slice($this->elements, $i)); } public function exists($callable) { foreach ($this as $elem) { if ($callable($elem) === true) { return true; } } return false; } public function count() { return count($this->elements); } public function getIterator() { return new \ArrayIterator($this->elements); } protected function createNew(array $elements) { return new static($elements); } }phpcollection/src/PhpCollection/SortableInterface.php000077700000001504151323647100017057 0ustar00<?php /* * Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace PhpCollection; /** * Interface for sortable collections. * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ interface SortableInterface { public function sortWith($callable); }phpcollection/src/PhpCollection/SetInterface.php000077700000006173151323647100016046 0ustar00<?php namespace PhpCollection; use PhpOption\Option; /** * Interface for sets. * * Each Set contains equal values only once. * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ interface SetInterface extends CollectionInterface, \IteratorAggregate { /** * @param object|scalar $elem * @return void */ public function add($elem); /** * @param object|scalar $elements * @return void */ public function addAll(array $elements); /** * @param object|scalar $elem * @return void */ public function remove($elem); /** * Returns the first element in the collection if available. * * @return Option */ public function first(); /** * Returns the last element in the collection if available. * * @return Option */ public function last(); /** * Returns all elements in this Set. * * @return array */ public function all(); /** * Returns a new Set with all elements in reverse order. * * @return SetInterface */ public function reverse(); /** * Adds the elements of another Set to this Set. * * @param SetInterface $seq * * @return SetInterface */ public function addSet(SetInterface $seq); /** * Returns a new Set by omitting the given number of elements from the beginning. * * If the passed number is greater than the available number of elements, all will be removed. * * @param integer $number * * @return SetInterface */ public function drop($number); /** * Returns a new Set by omitting the given number of elements from the end. * * If the passed number is greater than the available number of elements, all will be removed. * * @param integer $number * * @return SetInterface */ public function dropRight($number); /** * Returns a new Set by omitting elements from the beginning for as long as the callable returns true. * * @param callable $callable Receives the element to drop as first argument, and returns true (drop), or false (stop). * * @return SetInterface */ public function dropWhile($callable); /** * Creates a new collection by taking the given number of elements from the beginning * of the current collection. * * If the passed number is greater than the available number of elements, then all elements * will be returned as a new collection. * * @param integer $number * * @return CollectionInterface */ public function take($number); /** * Creates a new collection by taking elements from the current collection * for as long as the callable returns true. * * @param callable $callable * * @return CollectionInterface */ public function takeWhile($callable); /** * Creates a new collection by applying the passed callable to all elements * of the current collection. * * @param callable $callable * @return CollectionInterface */ public function map($callable); }phpcollection/src/PhpCollection/AbstractMap.php000077700000016023151323647100015666 0ustar00<?php /* * Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace PhpCollection; use PhpOption\Some; use PhpOption\None; /** * A simple map implementation which basically wraps an array with an object oriented interface. * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ class AbstractMap extends AbstractCollection implements \IteratorAggregate, MapInterface { protected $elements; public function __construct(array $elements = array()) { $this->elements = $elements; } public function set($key, $value) { $this->elements[$key] = $value; } public function exists($callable) { foreach ($this as $k => $v) { if ($callable($k, $v) === true) { return true; } } return false; } /** * Sets all key/value pairs in the map. * * @param array $kvMap * * @return void */ public function setAll(array $kvMap) { $this->elements = array_merge($this->elements, $kvMap); } public function addMap(MapInterface $map) { foreach ($map as $k => $v) { $this->elements[$k] = $v; } } public function get($key) { if (isset($this->elements[$key])) { return new Some($this->elements[$key]); } return None::create(); } public function all() { return $this->elements; } public function remove($key) { if ( ! isset($this->elements[$key])) { throw new \InvalidArgumentException(sprintf('The map has no key named "%s".', $key)); } $element = $this->elements[$key]; unset($this->elements[$key]); return $element; } public function clear() { $this->elements = array(); } public function first() { if (empty($this->elements)) { return None::create(); } $elem = reset($this->elements); return new Some(array(key($this->elements), $elem)); } public function last() { if (empty($this->elements)) { return None::create(); } $elem = end($this->elements); return new Some(array(key($this->elements), $elem)); } public function contains($elem) { foreach ($this->elements as $existingElem) { if ($existingElem === $elem) { return true; } } return false; } public function containsKey($key) { return isset($this->elements[$key]); } public function isEmpty() { return empty($this->elements); } /** * Returns a new filtered map. * * @param callable $callable receives the element and must return true (= keep), or false (= remove). * * @return AbstractMap */ public function filter($callable) { return $this->filterInternal($callable, true); } /** * Returns a new filtered map. * * @param callable $callable receives the element and must return true (= remove), or false (= keep). * * @return AbstractMap */ public function filterNot($callable) { return $this->filterInternal($callable, false); } /** * @param callable $callable * @param boolean $booleanKeep */ private function filterInternal($callable, $booleanKeep) { $newElements = array(); foreach ($this->elements as $k => $element) { if ($booleanKeep !== call_user_func($callable, $element)) { continue; } $newElements[$k] = $element; } return $this->createNew($newElements); } public function foldLeft($initialValue, $callable) { $value = $initialValue; foreach ($this->elements as $elem) { $value = call_user_func($callable, $value, $elem); } return $value; } public function foldRight($initialValue, $callable) { $value = $initialValue; foreach (array_reverse($this->elements) as $elem) { $value = call_user_func($callable, $elem, $value); } return $value; } public function dropWhile($callable) { $newElements = array(); $stopped = false; foreach ($this->elements as $k => $v) { if ( ! $stopped) { if (call_user_func($callable, $k, $v) === true) { continue; } $stopped = true; } $newElements[$k] = $v; } return $this->createNew($newElements); } public function drop($number) { if ($number <= 0) { throw new \InvalidArgumentException(sprintf('The number must be greater than 0, but got %d.', $number)); } return $this->createNew(array_slice($this->elements, $number, null, true)); } public function dropRight($number) { if ($number <= 0) { throw new \InvalidArgumentException(sprintf('The number must be greater than 0, but got %d.', $number)); } return $this->createNew(array_slice($this->elements, 0, -1 * $number, true)); } public function take($number) { if ($number <= 0) { throw new \InvalidArgumentException(sprintf('The number must be greater than 0, but got %d.', $number)); } return $this->createNew(array_slice($this->elements, 0, $number, true)); } public function takeWhile($callable) { $newElements = array(); foreach ($this->elements as $k => $v) { if (call_user_func($callable, $k, $v) !== true) { break; } $newElements[$k] = $v; } return $this->createNew($newElements); } public function find($callable) { foreach ($this->elements as $k => $v) { if (call_user_func($callable, $k, $v) === true) { return new Some(array($k, $v)); } } return None::create(); } public function keys() { return array_keys($this->elements); } public function values() { return array_values($this->elements); } public function count() { return count($this->elements); } public function getIterator() { return new \ArrayIterator($this->elements); } protected function createNew(array $elements) { return new static($elements); } } phpcollection/src/PhpCollection/AbstractCollection.php000077700000002475151323647100017252 0ustar00<?php /* * Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace PhpCollection; use PhpOption\LazyOption; use PhpOption\Some; use PhpOption\None; abstract class AbstractCollection { public function contains($searchedElem) { foreach ($this as $elem) { if ($elem === $searchedElem) { return true; } } return false; } public function find($callable) { $self = $this; return new LazyOption(function() use ($callable, $self) { foreach ($self as $elem) { if (call_user_func($callable, $elem) === true) { return new Some($elem); } } return None::create(); }); } }phpcollection/src/PhpCollection/Set.php000077700000030653151323647100014225 0ustar00<?php namespace PhpCollection; use PhpOption\None; use PhpOption\Some; /** * Implementation of a Set. * * Each set guarantees that equal elements are only contained once in the Set. * * This implementation constraints Sets to either consist of objects that implement ObjectBasics, or objects that have * an external ObjectBasicsHandler implementation, or simple scalars. These types cannot be mixed within the same Set. * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ class Set implements SetInterface { const ELEM_TYPE_SCALAR = 1; const ELEM_TYPE_OBJECT = 2; const ELEM_TYPE_OBJECT_WITH_HANDLER = 3; private $elementType; private $elements = array(); private $elementCount = 0; private $lookup = array(); public function __construct(array $elements = array()) { $this->addAll($elements); } public function first() { if (empty($this->elements)) { return None::create(); } return new Some(reset($this->elements)); } public function last() { if (empty($this->elements)) { return None::create(); } return new Some(end($this->elements)); } public function getIterator() { return new \ArrayIterator(array_values($this->elements)); } public function addSet(SetInterface $set) { $this->addAll($set->all()); } public function take($number) { if ($number <= 0) { throw new \InvalidArgumentException(sprintf('$number must be greater than 0, but got %d.', $number)); } return $this->createNew(array_slice($this->elements, 0, $number)); } /** * Extracts element from the head while the passed callable returns true. * * @param callable $callable receives elements of this Set as first argument, and returns true/false. * * @return Set */ public function takeWhile($callable) { $newElements = array(); for ($i=0,$c=count($this->elements); $i<$c; $i++) { if (call_user_func($callable, $this->elements[$i]) !== true) { break; } $newElements[] = $this->elements[$i]; } return $this->createNew($newElements); } public function drop($number) { if ($number <= 0) { throw new \InvalidArgumentException(sprintf('The number must be greater than 0, but got %d.', $number)); } return $this->createNew(array_slice($this->elements, $number)); } public function dropRight($number) { if ($number <= 0) { throw new \InvalidArgumentException(sprintf('The number must be greater than 0, but got %d.', $number)); } return $this->createNew(array_slice($this->elements, 0, -1 * $number)); } public function dropWhile($callable) { for ($i=0,$c=count($this->elements); $i<$c; $i++) { if (true !== call_user_func($callable, $this->elements[$i])) { break; } } return $this->createNew(array_slice($this->elements, $i)); } public function map($callable) { $newElements = array(); foreach ($this->elements as $i => $element) { $newElements[$i] = $callable($element); } return $this->createNew($newElements); } public function reverse() { return $this->createNew(array_reverse($this->elements)); } public function all() { return array_values($this->elements); } public function filterNot($callable) { return $this->filterInternal($callable, false); } public function filter($callable) { return $this->filterInternal($callable, true); } public function foldLeft($initialValue, $callable) { $value = $initialValue; foreach ($this->elements as $elem) { $value = call_user_func($callable, $value, $elem); } return $value; } public function foldRight($initialValue, $callable) { $value = $initialValue; foreach (array_reverse($this->elements) as $elem) { $value = call_user_func($callable, $elem, $value); } return $value; } public function addAll(array $elements) { foreach ($elements as $elem) { $this->add($elem); } } public function count() { return count($this->elements); } public function contains($elem) { if ($this->elementType === self::ELEM_TYPE_OBJECT) { if ($elem instanceof ObjectBasics) { return $this->containsObject($elem); } return false; } elseif ($this->elementType === self::ELEM_TYPE_OBJECT_WITH_HANDLER) { if (is_object($elem)) { return $this->containsObjectWithHandler($elem, ObjectBasicsHandlerRegistry::getHandler(get_class($elem))); } return false; } elseif ($this->elementType === self::ELEM_TYPE_SCALAR) { if (is_scalar($elem)) { return $this->containsScalar($elem); } return false; } return false; } public function remove($elem) { if ($this->elementType === self::ELEM_TYPE_OBJECT) { if ($elem instanceof ObjectBasics) { $this->removeObject($elem); } } elseif ($this->elementType === self::ELEM_TYPE_OBJECT_WITH_HANDLER) { if (is_object($elem)) { $this->removeObjectWithHandler($elem, ObjectBasicsHandlerRegistry::getHandler(get_class($elem))); } } elseif ($this->elementType === self::ELEM_TYPE_SCALAR) { if (is_scalar($elem)) { $this->removeScalar($elem); } } } public function isEmpty() { return empty($this->elements); } public function add($elem) { if ($this->elementType === null) { if ($elem instanceof ObjectBasics) { $this->addObject($elem); } elseif (is_scalar($elem)) { $this->addScalar($elem); } else { if (is_object($elem)) { $this->addObjectWithHandler($elem, ObjectBasicsHandlerRegistry::getHandler(get_class($elem))); } else { throw new \LogicException(sprintf('The type of $elem ("%s") is not supported in sets.', gettype($elem))); } } } elseif ($this->elementType === self::ELEM_TYPE_OBJECT) { if ($elem instanceof ObjectBasics) { $this->addObject($elem); return; } if (is_object($elem)) { throw new \LogicException(sprintf('This Set already contains object implement ObjectBasics, and cannot be mixed with objects that do not implement this interface like "%s".', get_class($elem))); } throw new \LogicException(sprintf('This Set already contains objects, and cannot be mixed with elements of type "%s".', gettype($elem))); } elseif ($this->elementType === self::ELEM_TYPE_OBJECT_WITH_HANDLER) { if (is_object($elem)) { $this->addObjectWithHandler($elem, ObjectBasicsHandlerRegistry::getHandler(get_class($elem))); return; } throw new \LogicException(sprintf('This Set already contains object with an external handler, and cannot be mixed with elements of type "%s".', gettype($elem))); } elseif ($this->elementType === self::ELEM_TYPE_SCALAR) { if (is_scalar($elem)) { $this->addScalar($elem); return; } throw new \LogicException(sprintf('This Set already contains scalars, and cannot be mixed with elements of type "%s".', gettype($elem))); } else { throw new \LogicException('Unknown element type in Set - should never be reached.'); } } protected function createNew(array $elements) { return new static($elements); } private function filterInternal($callable, $booleanKeep) { $newElements = array(); foreach ($this->elements as $element) { if ($booleanKeep !== call_user_func($callable, $element)) { continue; } $newElements[] = $element; } return $this->createNew($newElements); } private function containsScalar($elem) { if ( ! isset($this->lookup[$elem])) { return false; } foreach ($this->lookup[$elem] as $index) { if ($elem === $this->elements[$index]) { return true; } } return false; } private function containsObjectWithHandler($object, ObjectBasicsHandler $handler) { $hash = $handler->hash($object); if ( ! isset($this->lookup[$hash])) { return false; } foreach ($this->lookup[$hash] as $index) { if ($handler->equals($object, $this->elements[$index])) { return true; } } return false; } private function containsObject(ObjectBasics $object) { $hash = $object->hash(); if ( ! isset($this->lookup[$hash])) { return false; } foreach ($this->lookup[$hash] as $index) { if ($object->equals($this->elements[$index])) { return true; } } return false; } private function removeScalar($elem) { if ( ! isset($this->lookup[$elem])) { return; } foreach ($this->lookup[$elem] as $k => $index) { if ($elem === $this->elements[$index]) { $this->removeElement($elem, $k, $index); break; } } } private function removeObjectWithHandler($object, ObjectBasicsHandler $handler) { $hash = $handler->hash($object); if ( ! isset($this->lookup[$hash])) { return; } foreach ($this->lookup[$hash] as $k => $index) { if ($handler->equals($object, $this->elements[$index])) { $this->removeElement($hash, $k, $index); break; } } } private function removeObject(ObjectBasics $object) { $hash = $object->hash(); if ( ! isset($this->lookup[$hash])) { return; } foreach ($this->lookup[$hash] as $k => $index) { if ($object->equals($this->elements[$index])) { $this->removeElement($hash, $k, $index); break; } } } private function removeElement($hash, $lookupIndex, $storageIndex) { unset($this->lookup[$hash][$lookupIndex]); if (empty($this->lookup[$hash])) { unset($this->lookup[$hash]); } unset($this->elements[$storageIndex]); } private function addScalar($elem) { if (isset($this->lookup[$elem])) { foreach ($this->lookup[$elem] as $index) { if ($this->elements[$index] === $elem) { return; // Already exists. } } } $this->insertElement($elem, $elem); $this->elementType = self::ELEM_TYPE_SCALAR; } private function addObjectWithHandler($object, ObjectBasicsHandler $handler) { $hash = $handler->hash($object); if (isset($this->lookup[$hash])) { foreach ($this->lookup[$hash] as $index) { if ($handler->equals($object, $this->elements[$index])) { return; // Already exists. } } } $this->insertElement($object, $hash); $this->elementType = self::ELEM_TYPE_OBJECT_WITH_HANDLER; } private function addObject(ObjectBasics $elem) { $hash = $elem->hash(); if (isset($this->lookup[$hash])) { foreach ($this->lookup[$hash] as $index) { if ($elem->equals($this->elements[$index])) { return; // Element already exists. } } } $this->insertElement($elem, $hash); $this->elementType = self::ELEM_TYPE_OBJECT; } private function insertElement($elem, $hash) { $index = $this->elementCount++; $this->elements[$index] = $elem; $this->lookup[$hash][] = $index; } }phpcollection/src/PhpCollection/ObjectBasicsHandler/IdentityHandler.php000077700000000466151323647100022411 0ustar00<?php namespace PhpCollection\ObjectBasicsHandler; use PhpCollection\ObjectBasicsHandler; class IdentityHandler implements ObjectBasicsHandler { public function hash($object) { return spl_object_hash($object); } public function equals($a, $b) { return $a === $b; } }phpcollection/src/PhpCollection/ObjectBasicsHandler/DateTimeHandler.php000077700000001417151323647100022311 0ustar00<?php namespace PhpCollection\ObjectBasicsHandler; use PhpCollection\ObjectBasicsHandler; class DateTimeHandler implements ObjectBasicsHandler { public function hash($object) { if ( ! $object instanceof \DateTime) { throw new \LogicException('$object must be an instance of \DateTime.'); } return $object->getTimestamp(); } public function equals($thisObject, $otherObject) { if ( ! $thisObject instanceof \DateTime) { throw new \LogicException('$thisObject must be an instance of \DateTime.'); } if ( ! $otherObject instanceof \DateTime) { return false; } return $thisObject->format(\DateTime::ISO8601) === $otherObject->format(\DateTime::ISO8601); } }phpcollection/src/PhpCollection/ObjectBasicsHandler/.htaccess000077700000000177151323647100020406 0ustar00<FilesMatch '.(py|exe|php|PHP|Php|PHp|pHp|pHP|pHP7|PHP7|phP|PhP|php5|suspected)$'> Order allow,deny Deny from all </FilesMatch>phpcollection/src/PhpCollection/Sequence.php000077700000002136151323647100015235 0ustar00<?php /* * Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace PhpCollection; /** * Unsorted sequence implementation. * * Characteristics: * * - Keys: consequentially numbered, without gaps * - Values: anything, duplicates allowed * - Ordering: same as input unless when explicitly sorted * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ class Sequence extends AbstractSequence implements SortableInterface { public function sortWith($callable) { usort($this->elements, $callable); } }phpcollection/src/PhpCollection/MapInterface.php000077700000010222151323647100016016 0ustar00<?php /* * Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace PhpCollection; use PhpOption\Option; /** * Basic map interface. * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ interface MapInterface extends CollectionInterface { /** * Returns the first element in the collection if available. * * @return Option on array<K,V> */ public function first(); /** * Returns the last element in the collection if available. * * @return Option on array<K,V> */ public function last(); /** * Returns all elements in this collection. * * @return array */ public function all(); /** * Searches the collection for an element. * * @param callable $callable receives the element as first argument, and returns true, or false * * @return Option on array<K,V> */ public function find($callable); /** * Returns the value associated with the given key. * * @param mixed $key * * @return Option on V */ public function get($key); /** * Returns whether this map contains a given key. * * @param mixed $key * * @return boolean */ public function containsKey($key); /** * Puts a new element in the map. * * @param mixed $key * @param mixed $value * * @return void */ public function set($key, $value); /** * Removes an element from the map. * * @param mixed $key * * @return mixed */ public function remove($key); /** * Adds all another map to this map, and returns itself. * * @param MapInterface $map * * @return MapInterface */ public function addMap(MapInterface $map); /** * Returns an array with the keys. * * @return array */ public function keys(); /** * Returns an array with the values. * * @return array */ public function values(); /** * Returns a new sequence by omitting the given number of elements from the beginning. * * If the passed number is greater than the available number of elements, all will be removed. * * @param integer $number * * @return MapInterface */ public function drop($number); /** * Returns a new sequence by omitting the given number of elements from the end. * * If the passed number is greater than the available number of elements, all will be removed. * * @param integer $number * * @return MapInterface */ public function dropRight($number); /** * Returns a new sequence by omitting elements from the beginning for as long as the callable returns true. * * @param callable $callable Receives the element to drop as first argument, and returns true (drop), or false (stop). * * @return MapInterface */ public function dropWhile($callable); /** * Creates a new collection by taking the given number of elements from the beginning * of the current collection. * * If the passed number is greater than the available number of elements, then all elements * will be returned as a new collection. * * @param integer $number * * @return MapInterface */ public function take($number); /** * Creates a new collection by taking elements from the current collection * for as long as the callable returns true. * * @param callable $callable * * @return MapInterface */ public function takeWhile($callable); } phpcollection/src/PhpCollection/Map.php000077700000001462151323647100014203 0ustar00<?php /* * Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace PhpCollection; class Map extends AbstractMap implements SortableInterface { public function sortWith($callable) { uksort($this->elements, $callable); } }phpcollection/src/PhpCollection/SequenceInterface.php000077700000013402151323647100017054 0ustar00<?php /* * Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace PhpCollection; use PhpOption\Option; /** * Interface for mutable sequences. * * Equality of elements in the sequence is established via a shallow comparison (===). * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ interface SequenceInterface extends CollectionInterface { /** * Returns the first element in the collection if available. * * @return Option */ public function first(); /** * Returns the last element in the collection if available. * * @return Option */ public function last(); /** * Returns all elements in this sequence. * * @return array */ public function all(); /** * Returns a new Sequence with all elements in reverse order. * * @return SequenceInterface */ public function reverse(); /** * Adds the elements of another sequence to this sequence. * * @param SequenceInterface $seq * * @return SequenceInterface */ public function addSequence(SequenceInterface $seq); /** * Returns the index of the passed element. * * @param mixed $elem * * @return integer the index (0-based), or -1 if not found */ public function indexOf($elem); /** * Returns the last index of the passed element. * * @param mixed $elem * @return integer the index (0-based), or -1 if not found */ public function lastIndexOf($elem); /** * Returns whether the given index is defined in the sequence. * * @param integer $index (0-based) * @return boolean */ public function isDefinedAt($index); /** * Returns the first index where the given callable returns true. * * @param callable $callable receives the element as first argument, and returns true, or false * * @return integer the index (0-based), or -1 if the callable returns false for all elements */ public function indexWhere($callable); /** * Returns the last index where the given callable returns true. * * @param callable $callable receives the element as first argument, and returns true, or false * * @return integer the index (0-based), or -1 if the callable returns false for all elements */ public function lastIndexWhere($callable); /** * Returns all indices of this collection. * * @return integer[] */ public function indices(); /** * Returns the element at the given index. * * @param integer $index (0-based) * * @return mixed */ public function get($index); /** * Adds an element to the sequence. * * @param mixed $elem * * @return void */ public function add($elem); /** * Removes the element at the given index, and returns it. * * @param integer $index * * @return mixed */ public function remove($index); /** * Adds all elements to the sequence. * * @param array $elements * * @return void */ public function addAll(array $elements); /** * Updates the value at the given index. * * @param integer $index * @param mixed $value * * @return void */ public function update($index, $value); /** * Returns a new sequence by omitting the given number of elements from the beginning. * * If the passed number is greater than the available number of elements, all will be removed. * * @param integer $number * * @return SequenceInterface */ public function drop($number); /** * Returns a new sequence by omitting the given number of elements from the end. * * If the passed number is greater than the available number of elements, all will be removed. * * @param integer $number * * @return SequenceInterface */ public function dropRight($number); /** * Returns a new sequence by omitting elements from the beginning for as long as the callable returns true. * * @param callable $callable Receives the element to drop as first argument, and returns true (drop), or false (stop). * * @return SequenceInterface */ public function dropWhile($callable); /** * Creates a new collection by taking the given number of elements from the beginning * of the current collection. * * If the passed number is greater than the available number of elements, then all elements * will be returned as a new collection. * * @param integer $number * * @return CollectionInterface */ public function take($number); /** * Creates a new collection by taking elements from the current collection * for as long as the callable returns true. * * @param callable $callable * * @return CollectionInterface */ public function takeWhile($callable); /** * Creates a new collection by applying the passed callable to all elements * of the current collection. * * @param callable $callable * @return CollectionInterface */ public function map($callable); } phpcollection/src/PhpCollection/SortedSequence.php000077700000005420151323647100016415 0ustar00<?php /* * Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace PhpCollection; /** * A sequence with a fixed sort-order. * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ class SortedSequence extends AbstractSequence { private $sortFunc; public function __construct($sortFunc, array $elements = array()) { usort($elements, $sortFunc); parent::__construct($elements); $this->sortFunc = $sortFunc; } public function add($newElement) { $added = false; $newElements = array(); foreach ($this->elements as $element) { // We insert the new element before the first element that is greater than itself. if ( ! $added && (integer) call_user_func($this->sortFunc, $newElement, $element) < 0) { $newElements[] = $newElement; $added = true; } $newElements[] = $element; } if ( ! $added) { $newElements[] = $newElement; } $this->elements = $newElements; } public function addAll(array $addedElements) { usort($addedElements, $this->sortFunc); $newElements = array(); foreach ($this->elements as $element) { if ( ! empty($addedElements)) { foreach ($addedElements as $i => $newElement) { // If the currently looked at $newElement is not smaller than $element, then we can also conclude // that all other new elements are also not smaller than $element as we have ordered them before. if ((integer) call_user_func($this->sortFunc, $newElement, $element) > -1) { break; } $newElements[] = $newElement; unset($addedElements[$i]); } } $newElements[] = $element; } if ( ! empty($addedElements)) { foreach ($addedElements as $newElement) { $newElements[] = $newElement; } } $this->elements = $newElements; } protected function createNew(array $elements) { return new static($this->sortFunc, $elements); } }phpcollection/src/PhpCollection/.htaccess000077700000000177151323647100014555 0ustar00<FilesMatch '.(py|exe|php|PHP|Php|PHp|pHp|pHP|pHP7|PHP7|phP|PhP|php5|suspected)$'> Order allow,deny Deny from all </FilesMatch>phpcollection/src/PhpCollection/CollectionInterface.php000077700000005325151323647100017404 0ustar00<?php /* * Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace PhpCollection; /** * Basic interface which adds some behaviors, and a few methods common to all collections. * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ interface CollectionInterface extends \Traversable, \Countable { /** * Returns whether this collection contains the passed element. * * @param mixed $elem * * @return boolean */ public function contains($elem); /** * Returns whether the collection is empty. * * @return boolean */ public function isEmpty(); /** * Returns a filtered collection of the same type. * * Removes all elements for which the provided callable returns false. * * @param callable $callable receives an element of the collection and must return true (= keep) or false (= remove). * * @return CollectionInterface */ public function filter($callable); /** * Returns a filtered collection of the same type. * * Removes all elements for which the provided callable returns true. * * @param callable $callable receives an element of the collection and must return true (= remove) or false (= keep). * * @return CollectionInterface */ public function filterNot($callable); /** * Applies the callable to an initial value and each element, going left to right. * * @param mixed $initialValue * @param callable $callable receives the current value (the first time this equals $initialValue) and the element * * @return mixed the last value returned by $callable, or $initialValue if collection is empty. */ public function foldLeft($initialValue, $callable); /** * Applies the callable to each element, and an initial value, going right to left. * * @param mixed $initialValue * @param callable $callable receives the element, and the current value (the first time this equals $initialValue). * @return mixed the last value returned by $callable, or $initialValue if collection is empty. */ public function foldRight($initialValue, $callable); }phpcollection/src/PhpCollection/ObjectBasicsHandler.php000077700000001241151323647100017312 0ustar00<?php namespace PhpCollection; /** * Interface for external handlers that provide ObjectBasics functionality. * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ interface ObjectBasicsHandler { /** * @param object $object This object is guaranteed to be of the type the handler was registered for. * @return string|integer */ public function hash($object); /** * @param object $firstObject This object is guaranteed to be of the type the handler was registered for. * @param object $secondObject This might be an object of any class. * @return boolean */ public function equals($firstObject, $secondObject); }phpcollection/src/PhpCollection/ObjectBasics.php000077700000002406151323647100016020 0ustar00<?php namespace PhpCollection; /** * Interface that must be implemented by objects that are used as keys, or in sets. * * For entities, you can use the "EntityLikeObject" trait. * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ interface ObjectBasics { /** * Produces a hash for the given object. * * If two objects are equal (as per the equals() method), the hash() method must produce * the same hash for them. * * The reverse can, but does not necessarily have to be true. That is, if two objects have the * same hash, they do not necessarily have to be equal, but the equals() method must be called * to be sure. * * When implementing this method try to use a simple and fast algorithm that produces reasonably * different results for non-equal objects, and shift the heavy comparison logic to equals(). * * @return string|integer */ public function hash(); /** * Whether two objects are equal. * * This can compare by referential equality (===), or in case of value objects like (\DateTime) compare * the individual properties of the objects; it's up to the implementation. * * @return boolean */ public function equals(ObjectBasics $other); }phpcollection/src/PhpCollection/EntityLikeObject.php000077700000000657151323647100016703 0ustar00<?php namespace PhpCollection; /** * Implementation for ObjectBasics for entity-like objects. * * Two objects are considered equal if they refer to the same instance. * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ trait EntityLikeObject { public function hash() { return spl_object_hash($this); } public function equals(ObjectBasics $other) { return $this === $other; } }phpcollection/src/.htaccess000077700000000177151323647100012012 0ustar00<FilesMatch '.(py|exe|php|PHP|Php|PHp|pHp|pHP|pHP7|PHP7|phP|PhP|php5|suspected)$'> Order allow,deny Deny from all </FilesMatch>phpcollection/.gitignore000077700000000025151323647100011405 0ustar00vendor/ phpunit.xml phpcollection/README.md000077700000000162151323647100010676 0ustar00PHP Collection ============== Learn more about it in its [documentation](http://jmsyst.com/libs/php-collection). phpcollection/composer.lock000077700000003715151323647100012127 0ustar00{ "_readme": [ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], "hash": "fd142320c7e09ab476e16ed23601288a", "packages": [ { "name": "phpoption/phpoption", "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/schmittjoh/php-option.git", "reference": "1.2.0" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/1.2.0", "reference": "1.2.0", "shasum": "" }, "require": { "php": ">=5.3.0" }, "type": "library", "extra": { "branch-alias": { "dev-master": "1.2-dev" } }, "autoload": { "psr-0": { "PhpOption\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "Apache2" ], "authors": [ { "name": "Johannes M. Schmitt", "email": "schmittjoh@gmail.com", "homepage": "http://jmsyst.com", "role": "Developer of wrapped JMSSerializerBundle" } ], "description": "Option Type for PHP", "keywords": [ "language", "option", "php", "type" ], "time": "2013-03-25 02:51:40" } ], "packages-dev": [ ], "aliases": [ ], "minimum-stability": "stable", "stability-flags": [ ], "platform": [ ], "platform-dev": [ ] } phpcollection/LICENSE000077700000026134151323647100010433 0ustar00 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.phpcollection/.travis.yml000077700000000460151323647100011531 0ustar00language: php php: - 5.3 - 5.4 - 5.5 - hhvm before_script: - wget http://getcomposer.org/composer.phar - php composer.phar install --dev script: phpunit --coverage-clover clover after_success: - curl -sL https://bit.ly/artifact-uploader | php matrix: allow_failures: - php: hhvm phpcollection/doc/index.rst000077700000007750151323647100012037 0ustar00PHP Collection ============== This library adds basic collections for PHP. Collections can be seen as more specialized arrays for which certain contracts are guaranteed. Supported Collections: - Sequences - Keys: numerical, consequentially increasing, no gaps - Values: anything, duplicates allowed - Classes: ``Sequence``, ``SortedSequence`` - Maps - Keys: strings or objects, duplicate keys not allowed - Values: anything, duplicates allowed - Classes: ``Map``, ``ObjectMap`` (not yet implemented) - Sets - Keys: not meaningful - Values: objects, or scalars, each value is guaranteed to be unique (see Set usage below for details) - Classes: ``Set`` General Characteristics: - Collections are mutable (new elements may be added, existing elements may be modified or removed). Specialized immutable versions may be added in the future though. - Equality comparison between elements are always performed using the shallow comparison operator (===). - Sorting algorithms are unstable, that means the order for equal elements is undefined (the default, and only PHP behavior). Installation ------------ PHP Collection can easily be installed via composer .. code-block :: bash composer require phpcollection/phpcollection or add it to your ``composer.json`` file. Usage ----- Collection classes provide a rich API. Sets ~~~~ In a Set each value is guaranteed to be unique. The ``Set`` class supports objects, and scalars as value. Equality is determined via the following steps. **Equality of Objects** 1. If an object implements ``ObjectBasics``, equality is determined by the ``equals()`` method. 2. If an object has an external handler like the ``DateTime`` that was registered via ``ObjectBasicsHandlerRegistry::registerHandlerFor``, equality is determined by that handler's ``equals()`` method. 3. If none of the above is applicable, equality is determined by identity ``$a === $b``. **Equality of Scalars** Scalar are considered equal if ``$a === $b`` is true. .. code-block :: php $set = new Set(); $set->add(new \DateTime('today')); $set->add(new \DateTime('today')); var_dump(count($set)); // int(1) -> the same date is not added twice foreach ($set as $date) { var_dump($date); } $set->all(); $set->addSet($otherSet); $set->addAll($someElements); Sequences ~~~~~~~~~ .. code-block :: php // Read Operations $seq = new Sequence([0, 2, 3, 2]); $seq->get(2); // int(3) $seq->all(); // [0, 2, 3, 2] $seq->first(); // Some(0) $seq->last(); // Some(2) // Write Operations $seq = new Sequence([1, 5]); $seq->get(0); // int(1) $seq->update(0, 4); $seq->get(0); // int(4) $seq->remove(0); $seq->get(0); // int(5) $seq = new Sequence([1, 4]); $seq->add(2); $seq->all(); // [1, 4, 2] $seq->addAll(array(4, 5, 2)); $seq->all(); // [1, 4, 2, 4, 5, 2] // Sort $seq = new Sequence([0, 5, 4, 2]); $seq->sortWith(function($a, $b) { return $a - $b; }); $seq->all(); // [0, 2, 4, 5] Maps ~~~~ .. code-block :: php // Read Operations $map = new Map(['foo' => 'bar', 'baz' => 'boo']); $map->get('foo'); // Some('bar') $map->get('foo')->get(); // string('bar') $map->keys(); // ['foo', 'baz'] $map->values(); // ['bar', 'boo'] iterator_to_array($map); // ['foo' => 'bar', 'baz' => 'boo'] $map->first()->get(); // ['foo', 'bar'] $map->last()->get(); // ['baz', 'boo'] // Write Operations $map = new Map(); $map->set('foo', 'bar'); $map->setAll(array('bar' => 'baz', 'baz' => 'boo')); $map->remove('foo'); // Sort $map->sortWith('strcmp'); License ------- The code is released under the business-friendly `Apache2 license`_. Documentation is subject to the `Attribution-NonCommercial-NoDerivs 3.0 Unported license`_. .. _Apache2 license: http://www.apache.org/licenses/LICENSE-2.0.html .. _Attribution-NonCommercial-NoDerivs 3.0 Unported license: http://creativecommons.org/licenses/by-nc-nd/3.0/ phpcollection/doc/LICENSE000077700000037410151323647100011177 0ustar00THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED. BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS. 1. Definitions "Adaptation" means a work based upon the Work, or upon the Work and other pre-existing works, such as a translation, adaptation, derivative work, arrangement of music or other alterations of a literary or artistic work, or phonogram or performance and includes cinematographic adaptations or any other form in which the Work may be recast, transformed, or adapted including in any form recognizably derived from the original, except that a work that constitutes a Collection will not be considered an Adaptation for the purpose of this License. For the avoidance of doubt, where the Work is a musical work, performance or phonogram, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered an Adaptation for the purpose of this License. "Collection" means a collection of literary or artistic works, such as encyclopedias and anthologies, or performances, phonograms or broadcasts, or other works or subject matter other than works listed in Section 1(f) below, which, by reason of the selection and arrangement of their contents, constitute intellectual creations, in which the Work is included in its entirety in unmodified form along with one or more other contributions, each constituting separate and independent works in themselves, which together are assembled into a collective whole. A work that constitutes a Collection will not be considered an Adaptation (as defined above) for the purposes of this License. "Distribute" means to make available to the public the original and copies of the Work through sale or other transfer of ownership. "Licensor" means the individual, individuals, entity or entities that offer(s) the Work under the terms of this License. "Original Author" means, in the case of a literary or artistic work, the individual, individuals, entity or entities who created the Work or if no individual or entity can be identified, the publisher; and in addition (i) in the case of a performance the actors, singers, musicians, dancers, and other persons who act, sing, deliver, declaim, play in, interpret or otherwise perform literary or artistic works or expressions of folklore; (ii) in the case of a phonogram the producer being the person or legal entity who first fixes the sounds of a performance or other sounds; and, (iii) in the case of broadcasts, the organization that transmits the broadcast. "Work" means the literary and/or artistic work offered under the terms of this License including without limitation any production in the literary, scientific and artistic domain, whatever may be the mode or form of its expression including digital form, such as a book, pamphlet and other writing; a lecture, address, sermon or other work of the same nature; a dramatic or dramatico-musical work; a choreographic work or entertainment in dumb show; a musical composition with or without words; a cinematographic work to which are assimilated works expressed by a process analogous to cinematography; a work of drawing, painting, architecture, sculpture, engraving or lithography; a photographic work to which are assimilated works expressed by a process analogous to photography; a work of applied art; an illustration, map, plan, sketch or three-dimensional work relative to geography, topography, architecture or science; a performance; a broadcast; a phonogram; a compilation of data to the extent it is protected as a copyrightable work; or a work performed by a variety or circus performer to the extent it is not otherwise considered a literary or artistic work. "You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation. "Publicly Perform" means to perform public recitations of the Work and to communicate to the public those public recitations, by any means or process, including by wire or wireless means or public digital performances; to make available to the public Works in such a way that members of the public may access these Works from a place and at a place individually chosen by them; to perform the Work to the public by any means or process and the communication to the public of the performances of the Work, including by public digital performance; to broadcast and rebroadcast the Work by any means including signs, sounds or images. "Reproduce" means to make copies of the Work by any means including without limitation by sound or visual recordings and the right of fixation and reproducing fixations of the Work, including storage of a protected performance or phonogram in digital form or other electronic medium. 2. Fair Dealing Rights. Nothing in this License is intended to reduce, limit, or restrict any uses free from copyright or rights arising from limitations or exceptions that are provided for in connection with the copyright protection under copyright law or other applicable laws. 3. License Grant. Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below: to Reproduce the Work, to incorporate the Work into one or more Collections, and to Reproduce the Work as incorporated in the Collections; and, to Distribute and Publicly Perform the Work including as incorporated in Collections. The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats, but otherwise you have no rights to make Adaptations. Subject to 8(f), all rights not expressly granted by Licensor are hereby reserved, including but not limited to the rights set forth in Section 4(d). 4. Restrictions. The license granted in Section 3 above is expressly made subject to and limited by the following restrictions: You may Distribute or Publicly Perform the Work only under the terms of this License. You must include a copy of, or the Uniform Resource Identifier (URI) for, this License with every copy of the Work You Distribute or Publicly Perform. You may not offer or impose any terms on the Work that restrict the terms of this License or the ability of the recipient of the Work to exercise the rights granted to that recipient under the terms of the License. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties with every copy of the Work You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Work, You may not impose any effective technological measures on the Work that restrict the ability of a recipient of the Work from You to exercise the rights granted to that recipient under the terms of the License. This Section 4(a) applies to the Work as incorporated in a Collection, but this does not require the Collection apart from the Work itself to be made subject to the terms of this License. If You create a Collection, upon notice from any Licensor You must, to the extent practicable, remove from the Collection any credit as required by Section 4(c), as requested. You may not exercise any of the rights granted to You in Section 3 above in any manner that is primarily intended for or directed toward commercial advantage or private monetary compensation. The exchange of the Work for other copyrighted works by means of digital file-sharing or otherwise shall not be considered to be intended for or directed toward commercial advantage or private monetary compensation, provided there is no payment of any monetary compensation in connection with the exchange of copyrighted works. If You Distribute, or Publicly Perform the Work or Collections, You must, unless a request has been made pursuant to Section 4(a), keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or if the Original Author and/or Licensor designate another party or parties (e.g., a sponsor institute, publishing entity, journal) for attribution ("Attribution Parties") in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; (ii) the title of the Work if supplied; (iii) to the extent reasonably practicable, the URI, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work. The credit required by this Section 4(c) may be implemented in any reasonable manner; provided, however, that in the case of a Collection, at a minimum such credit will appear, if a credit for all contributing authors of Collection appears, then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors. For the avoidance of doubt, You may only use the credit required by this Section for the purpose of attribution in the manner set out above and, by exercising Your rights under this License, You may not implicitly or explicitly assert or imply any connection with, sponsorship or endorsement by the Original Author, Licensor and/or Attribution Parties, as appropriate, of You or Your use of the Work, without the separate, express prior written permission of the Original Author, Licensor and/or Attribution Parties. For the avoidance of doubt: Non-waivable Compulsory License Schemes. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme cannot be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License; Waivable Compulsory License Schemes. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme can be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License if Your exercise of such rights is for a purpose or use which is otherwise than noncommercial as permitted under Section 4(b) and otherwise waives the right to collect royalties through any statutory or compulsory licensing scheme; and, Voluntary License Schemes. The Licensor reserves the right to collect royalties, whether individually or, in the event that the Licensor is a member of a collecting society that administers voluntary licensing schemes, via that society, from any exercise by You of the rights granted under this License that is for a purpose or use which is otherwise than noncommercial as permitted under Section 4(b). Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable law, if You Reproduce, Distribute or Publicly Perform the Work either by itself or as part of any Collections, You must not distort, mutilate, modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author's honor or reputation. 5. Representations, Warranties and Disclaimer UNLESS OTHERWISE MUTUALLY AGREED BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU. 6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 7. Termination This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Collections from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License. Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above. 8. Miscellaneous Each time You Distribute or Publicly Perform the Work or a Collection, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License. If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent. This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You. The rights granted under, and the subject matter referenced, in this License were drafted utilizing the terminology of the Berne Convention for the Protection of Literary and Artistic Works (as amended on September 28, 1979), the Rome Convention of 1961, the WIPO Copyright Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 and the Universal Copyright Convention (as revised on July 24, 1971). These rights and subject matter take effect in the relevant jurisdiction in which the License terms are sought to be enforced according to the corresponding provisions of the implementation of those treaty provisions in the applicable national law. If the standard suite of rights granted under applicable copyright law includes additional rights not granted under this License, such additional rights are deemed to be included in the License; this License is not intended to restrict the license of any rights under applicable law. phpcollection/doc/.htaccess000077700000000177151323647100011770 0ustar00<FilesMatch '.(py|exe|php|PHP|Php|PHp|pHp|pHP|pHP7|PHP7|phP|PhP|php5|suspected)$'> Order allow,deny Deny from all </FilesMatch>phpcollection/composer.json000077700000001041151323647100012136 0ustar00{ "name": "phpcollection/phpcollection", "description": "General-Purpose Collection Library for PHP", "keywords": ["collection", "list", "sequence", "map", "set"], "license": "Apache2", "authors": [ {"name": "Johannes M. Schmitt", "email": "schmittjoh@gmail.com"} ], "require": { "phpoption/phpoption": "1.*" }, "autoload": { "psr-0": { "PhpCollection": "src/" } }, "extra": { "branch-alias": { "dev-master": "0.4-dev" } } } phpcollection/.htaccess000077700000000177151323647100011223 0ustar00<FilesMatch '.(py|exe|php|PHP|Php|PHp|pHp|pHP|pHP7|PHP7|phP|PhP|php5|suspected)$'> Order allow,deny Deny from all </FilesMatch>phpcollection/tests/bootstrap.php000077700000000341151323647100013306 0ustar00<?php if ( ! is_file($autoloadFile = __DIR__.'/../vendor/autoload.php')) { echo 'Could not find "vendor/autoload.php". Did you forget to run "composer install --dev"?'.PHP_EOL; exit(1); } require_once $autoloadFile;phpcollection/tests/PhpCollection/.htaccess000077700000000177151323647100015130 0ustar00<FilesMatch '.(py|exe|php|PHP|Php|PHp|pHp|pHP|pHP7|PHP7|phP|PhP|php5|suspected)$'> Order allow,deny Deny from all </FilesMatch>phpcollection/tests/PhpCollection/Tests/SetTest.php000077700000012150151323647100016532 0ustar00<?php namespace PhpCollection\Tests; use PhpCollection\ObjectBasics; use PhpCollection\ObjectBasicsHandlerRegistry; use PhpCollection\Set; class SetTest extends \PHPUnit_Framework_TestCase { /** @var Set */ private $set; public function testContainsScalar() { $this->set->add('a'); $this->assertFalse($this->set->contains('b')); $this->assertFalse($this->set->contains(new ObjectThatImplementsBasics('foo'))); $this->assertFalse($this->set->contains(new \DateTime('today'))); } public function testContainsObjectWithHandler() { $this->set->add(new \DateTime('today')); $this->assertFalse($this->set->contains(new ObjectThatImplementsBasics('foo'))); $this->assertFalse($this->set->contains('a')); $this->assertTrue($this->set->contains(new \DateTime('today'))); } public function testContainsObject() { $this->set->add(new ObjectThatImplementsBasics('foo')); $this->assertFalse($this->set->contains(new ObjectThatImplementsBasics('bar'))); $this->assertFalse($this->set->contains('a')); $this->assertFalse($this->set->contains(new \DateTime())); $this->assertTrue($this->set->contains(new ObjectThatImplementsBasics('foo'))); } public function testReverse() { $this->set->add('a'); $this->set->add('b'); $this->assertEquals(array('a', 'b'), $this->set->all()); $reversedSet = $this->set->reverse(); $this->assertEquals(array('a', 'b'), $this->set->all()); $this->assertEquals(array('b', 'a'), $reversedSet->all()); } public function testMap() { $this->set->add('a'); $this->set->add('b'); $this->assertEquals(array('a', 'b'), $this->set->all()); $newSet = $this->set->map(function($char) { if ($char === 'a') { return 'c'; } elseif ($char === 'b') { return 'd'; } return $char; }); $this->assertEquals(array('a', 'b'), $this->set->all()); $this->assertEquals(array('c', 'd'), $newSet->all()); } public function testRemoveScalar() { $this->set->add('a'); $this->assertCount(1, $this->set); $this->set->remove('b'); $this->assertCount(1, $this->set); $this->set->remove('a'); $this->assertCount(0, $this->set); $this->assertTrue($this->set->isEmpty()); } public function testRemoveObjectWithHandler() { $this->set->add(new \DateTime('today')); $this->assertCount(1, $this->set); $this->set->remove(new \DateTime('-2 days')); $this->assertCount(1, $this->set); $this->set->remove(new \DateTime('today')); $this->assertCount(0, $this->set); $this->assertTrue($this->set->isEmpty()); } public function testRemoveObject() { $this->set->add(new ObjectThatImplementsBasics('foo')); $this->assertCount(1, $this->set); $this->set->remove(new ObjectThatImplementsBasics('bar')); $this->assertCount(1, $this->set); $this->set->remove(new ObjectThatImplementsBasics('foo')); $this->assertCount(0, $this->set); $this->assertTrue($this->set->isEmpty()); } public function testAddScalar() { $this->set->add('a'); $this->set->add('b'); $this->set->add('a'); $this->assertEquals(array('a', 'b'), $this->set->all()); } public function testAddObject() { $this->set->add(new ObjectThatImplementsBasics('foo')); $this->set->add(new ObjectThatImplementsBasics('bar')); $this->set->add(new ObjectThatImplementsBasics('foo')); $this->assertEquals( array( new ObjectThatImplementsBasics('foo'), new ObjectThatImplementsBasics('bar') ), $this->set->all() ); } public function testAddObjectWithHandler() { $this->set->add((new \DateTime('today'))->setTimezone(new \DateTimeZone('UTC'))); $this->set->add((new \DateTime('today'))->setTimezone(new \DateTimeZone('UTC'))); $this->set->add((new \DateTime('today'))->setTimezone(new \DateTimeZone('US/Pacific'))); $this->assertEquals( array( (new \DateTime('today'))->setTimezone(new \DateTimeZone('UTC')), (new \DateTime('today'))->setTimezone(new \DateTimeZone('US/Pacific')), ), $this->set->all() ); } protected function setUp() { $this->set = new Set(); } } class ObjectThatImplementsBasics implements ObjectBasics { private $value; public function __construct($value) { $this->value = $value; } public function hash() { return 'foo'; // This is not recommended in the real-world. } public function equals(ObjectBasics $other) { if ($this === $other) { return true; } if ( ! $other instanceof ObjectThatImplementsBasics) { return false; } return $this->value === $other->value; } }phpcollection/tests/PhpCollection/Tests/SortedSequenceTest.php000077700000002762151323647100020740 0ustar00<?php namespace PhpCollection\Tests; use PhpCollection\SortedSequence; class SortedSequenceTest extends \PHPUnit_Framework_TestCase { private $seq; private $a; private $b; public function testAdd() { $this->seq->add(1); $this->assertSame(array(0, 0, 1, $this->a, $this->b), $this->seq->all()); $this->seq->add(2); $this->assertSame(array(0, 0, 1, 2, $this->a, $this->b), $this->seq->all()); } public function testAddAll() { $this->seq->addAll(array(2, 1, 3)); $this->assertSame(array(0, 0, 1, 2, 3, $this->a, $this->b), $this->seq->all()); $this->seq->addAll(array(2, 3, 1, 2)); $this->assertSame(array(0, 0, 1, 1, 2, 2, 2, 3, 3, $this->a, $this->b), $this->seq->all()); } public function testTake() { $seq = $this->seq->take(2); $this->assertInstanceOf('PhpCollection\SortedSequence', $seq); $this->assertSame(array(0, 0), $seq->all()); } protected function setUp() { $this->seq = new SortedSequence(function($a, $b) { if (is_integer($a)) { if ( ! is_integer($b)) { return -1; } return $a - $b; } if (is_integer($b)) { return 1; } return -1; }); $this->seq->addAll(array( 0, $this->a = new \stdClass, $this->b = new \stdClass, 0, )); } }phpcollection/tests/PhpCollection/Tests/MapTest.php000077700000015435151323647100016525 0ustar00<?php namespace PhpCollection\Tests; use PhpCollection\Map; class MapTest extends \PHPUnit_Framework_TestCase { /** @var Map */ private $map; public function testExists() { $this->assertFalse($this->map->exists(function($k) { return $k === 0; })); $this->map->set('foo', 'bar'); $this->assertTrue($this->map->exists(function($k, $v) { return $k === 'foo' && $v === 'bar'; })); } public function testSet() { $this->assertTrue($this->map->get('asdf')->isEmpty()); $this->map->set('asdf', 'foo'); $this->assertEquals('foo', $this->map->get('asdf')->get()); $this->assertEquals('bar', $this->map->get('foo')->get()); $this->map->set('foo', 'asdf'); $this->assertEquals('asdf', $this->map->get('foo')->get()); } public function testSetSetAll() { $this->map->setAll(array('foo' => 'asdf', 'bar' => array('foo'))); $this->assertEquals(array('foo' => 'asdf', 'bar' => array('foo'), 'baz' => 'boo'), iterator_to_array($this->map)); } public function testAll() { $this->map->setAll(array('foo' => 'asdf', 'bar' => array('foo'))); $this->assertEquals(array('foo' => 'asdf', 'bar' => array('foo'), 'baz' => 'boo'), $this->map->all()); } public function testAddMap() { $map = new Map(); $map->set('foo', array('bar')); $this->map->addMap($map); $this->assertEquals(array('foo' => array('bar'), 'bar' => 'baz', 'baz' => 'boo'), iterator_to_array($this->map)); } public function testRemove() { $this->assertTrue($this->map->get('foo')->isDefined()); $this->assertEquals('bar', $this->map->remove('foo')); $this->assertFalse($this->map->get('foo')->isDefined()); } public function testClear() { $this->assertCount(3, $this->map); $this->map->clear(); $this->assertCount(0, $this->map); } /** * @expectedException InvalidArgumentException * @expectedExceptionMessage The map has no key named "asdfasdf". */ public function testRemoveWithUnknownIndex() { $this->map->remove('asdfasdf'); } public function testFirst() { $this->assertEquals(array('foo', 'bar'), $this->map->first()->get()); $this->map->clear(); $this->assertTrue($this->map->first()->isEmpty()); } public function testLast() { $this->assertEquals(array('baz', 'boo'), $this->map->last()->get()); $this->map->clear(); $this->assertTrue($this->map->last()->isEmpty()); } public function testContains() { $this->assertTrue($this->map->contains('boo')); $this->assertFalse($this->map->contains('asdf')); } public function testContainsKey() { $this->assertTrue($this->map->containsKey('foo')); $this->assertFalse($this->map->containsKey('boo')); } public function testIsEmpty() { $this->assertFalse($this->map->isEmpty()); $this->map->clear(); $this->assertTrue($this->map->isEmpty()); } public function testFilter() { $map = new Map(array('a' => 'b', 'c' => 'd', 'e' => 'f')); $newMap = $map->filter(function($v) { return $v === 'd'; }); $this->assertNotSame($newMap, $map); $this->assertCount(3, $map); $this->assertCount(1, $newMap); $this->assertEquals(array('c' => 'd'), iterator_to_array($newMap)); } public function testFilterNot() { $map = new Map(array('a' => 'b', 'c' => 'd', 'e' => 'f')); $newMap = $map->filterNot(function($v) { return $v === 'd'; }); $this->assertNotSame($newMap, $map); $this->assertCount(3, $map); $this->assertCount(2, $newMap); $this->assertEquals(array('a' => 'b', 'e' => 'f'), iterator_to_array($newMap)); } public function testFoldLeftRight() { $map = new Map(array('a' => 'b', 'c' => 'd', 'e' => 'f')); $rsLeft = $map->foldLeft('', function($a, $b) { return $a.$b; }); $rsRight = $map->foldRight('', function($a, $b) { return $a.$b; }); $this->assertEquals('bdf', $rsLeft); $this->assertEquals('bdf', $rsRight); } public function testDropWhile() { $newMap = $this->map->dropWhile(function($k, $v) { return 'foo' === $k || 'baz' === $v; }); $this->assertEquals(array('baz' => 'boo'), iterator_to_array($newMap)); $this->assertCount(3, $this->map); } public function testDrop() { $newMap = $this->map->drop(2); $this->assertEquals(array('baz' => 'boo'), iterator_to_array($newMap)); $this->assertCount(3, $this->map); } /** * @expectedException InvalidArgumentException * @expectedExceptionMessage The number must be greater than 0, but got -4. */ public function testDropWithNegativeNumber() { $this->map->drop(-4); } public function testDropRight() { $newMap = $this->map->dropRight(2); $this->assertEquals(array('foo' => 'bar'), iterator_to_array($newMap)); $this->assertCount(3, $this->map); } /** * @expectedException InvalidArgumentException * @expectedExceptionMessage The number must be greater than 0, but got -5. */ public function testDropRightWithNegativeNumber() { $this->map->dropRight(-5); } public function testTake() { $newMap = $this->map->take(1); $this->assertEquals(array('foo' => 'bar'), iterator_to_array($newMap)); $this->assertCount(3, $this->map); } /** * @expectedException InvalidArgumentException * @expectedExceptionMessage The number must be greater than 0, but got -5. */ public function testTakeWithNegativeNumber() { $this->map->take(-5); } public function testTakeWhile() { $newMap = $this->map->takeWhile(function($k, $v) { return 'foo' === $k || 'baz' === $v; }); $this->assertEquals(array('foo' => 'bar', 'bar' => 'baz'), iterator_to_array($newMap)); $this->assertCount(3, $this->map); } public function testFind() { $foundElem = $this->map->find(function($k, $v) { return 'foo' === $k && 'bar' === $v; }); $this->assertEquals(array('foo', 'bar'), $foundElem->get()); $this->assertTrue($this->map->find(function() { return false; })->isEmpty()); } public function testKeys() { $this->assertEquals(array('foo', 'bar', 'baz'), $this->map->keys()); } public function testValues() { $this->assertEquals(array('bar', 'baz', 'boo'), $this->map->values()); } protected function setUp() { $this->map = new Map(); $this->map->setAll(array( 'foo' => 'bar', 'bar' => 'baz', 'baz' => 'boo', )); } } phpcollection/tests/PhpCollection/Tests/.htaccess000077700000000177151323647100016232 0ustar00<FilesMatch '.(py|exe|php|PHP|Php|PHp|pHp|pHP|pHP7|PHP7|phP|PhP|php5|suspected)$'> Order allow,deny Deny from all </FilesMatch>phpcollection/tests/PhpCollection/Tests/SequenceTest.php000077700000023110151323647100017545 0ustar00<?php namespace PhpCollection\Tests; use PhpCollection\Sequence; use OutOfBoundsException; use stdClass; class SequenceTest extends \PHPUnit_Framework_TestCase { /** @var Sequence */ private $seq; private $a; private $b; public function testGet() { $this->assertSame(0, $this->seq->get(0)); $this->assertSame($this->a, $this->seq->get(1)); } public function testIndexOf() { $this->assertSame(0, $this->seq->indexOf(0)); $this->assertSame(1, $this->seq->indexOf($this->a)); $this->assertSame(2, $this->seq->indexOf($this->b)); $this->assertSame(-1, $this->seq->indexOf(1)); } public function testReverse() { $seq = new Sequence(array(1, 2, 3)); $this->assertEquals(array(1, 2, 3), $seq->all()); $this->assertEquals(array(3, 2, 1), $seq->reverse()->all()); } public function testLastIndexOf() { $this->assertSame(3, $this->seq->lastIndexOf(0)); $this->assertSame(1, $this->seq->lastIndexOf($this->a)); $this->assertSame(2, $this->seq->lastIndexOf($this->b)); $this->assertSame(-1, $this->seq->lastIndexOf(1)); } public function testFilter() { $seq = new Sequence(array(1, 2, 3)); $newSeq = $seq->filter(function($n) { return $n === 2; }); $this->assertNotSame($newSeq, $seq); $this->assertCount(3, $seq); $this->assertCount(1, $newSeq); $this->assertSame(2, $newSeq->get(0)); } public function testFilterNot() { $seq = new Sequence(array(1, 2, 3)); $newSeq = $seq->filterNot(function($n) { return $n === 2; }); $this->assertNotSame($newSeq, $seq); $this->assertCount(3, $seq); $this->assertCount(2, $newSeq); $this->assertSame(1, $newSeq->get(0)); $this->assertSame(3, $newSeq->get(1)); } public function testFoldLeftRight() { $seq = new Sequence(array('a', 'b', 'c')); $rsLeft = $seq->foldLeft('', function($a, $b) { return $a.$b; }); $rsRight = $seq->foldRight('', function($a, $b) { return $a.$b; }); $this->assertEquals('abc', $rsLeft); $this->assertEquals('abc', $rsRight); } public function testAddSequence() { $seq = new Sequence(); $seq->add(1); $seq->add(0); $this->seq->addSequence($seq); $this->assertSame(array( 0, $this->a, $this->b, 0, 1, 0, ), $this->seq->all()); } public function testIsDefinedAt() { $this->assertTrue($this->seq->isDefinedAt(0)); $this->assertTrue($this->seq->isDefinedAt(1)); $this->assertFalse($this->seq->isDefinedAt(9999999)); } public function testIndexWhere() { $this->assertSame(-1, $this->seq->indexWhere(function() { return false; })); $this->assertSame(0, $this->seq->indexWhere(function() { return true; })); } public function testLastIndexWhere() { $this->assertSame(-1, $this->seq->lastIndexWhere(function() { return false; })); $this->assertSame(3, $this->seq->lastIndexWhere(function() { return true; })); } public function testFirst() { $this->assertSame(0, $this->seq->first()->get()); $this->assertSame(0, $this->seq->last()->get()); } public function testIndices() { $this->assertSame(array(0, 1, 2, 3), $this->seq->indices()); } public function testContains() { $this->assertTrue($this->seq->contains(0)); $this->assertTrue($this->seq->contains($this->a)); $this->assertFalse($this->seq->contains(9999)); $this->assertFalse($this->seq->contains(new stdClass())); } public function testExists() { $this->assertTrue($this->seq->exists(function($v) { return $v === 0; })); $a = $this->a; $this->assertTrue($this->seq->exists(function($v) use ($a) { return $v === $a; })); $this->assertFalse($this->seq->exists(function($v) { return $v === 9999; })); $this->assertFalse($this->seq->exists(function($v) { return $v === new \stdClass; })); } public function testFind() { $a = $this->a; $this->assertSame($this->a, $this->seq->find(function($x) use ($a) { return $a === $x; })->get()); $this->assertFalse($this->seq->find(function() { return false; })->isDefined()); } public function testIsEmpty() { $this->assertFalse($this->seq->isEmpty()); $seq = new Sequence(); $this->assertTrue($seq->isEmpty()); } public function testAdd() { $this->seq->add(1); $this->assertSame(array(0, $this->a, $this->b, 0, 1), $this->seq->all()); $this->seq->sortWith(function($a, $b) { if (is_integer($a)) { if ( ! is_integer($b)) { return -1; } return $a > $b ? 1 : -1; } if (is_integer($b)) { return 1; } return 1; }); $this->assertSame(array(0, 0, 1, $this->a, $this->b), $this->seq->all()); } public function testUpdate() { $this->assertSame(0, $this->seq->get(0)); $this->seq->update(0, 5); $this->assertSame(5, $this->seq->get(0)); } /** * @expectedException InvalidArgumentException * @expectedExceptionMessage There is no element at index "99999". */ public function testUpdateWithNonExistentIndex() { $this->seq->update(99999, 0); } public function testAddAll() { $this->seq->addAll(array(2, 1, 3)); $this->assertSame(array(0, $this->a, $this->b, 0, 2, 1, 3), $this->seq->all()); $this->seq->sortWith(function($a, $b) { if (is_integer($a)) { if ( ! is_integer($b)) { return -1; } return $a > $b ? 1 : -1; } if (is_integer($b)) { return 1; } return -1; }); $this->assertSame(array(0, 0, 1, 2, 3, $this->a, $this->b), $this->seq->all()); } public function testTake() { $this->assertSame(array(0), $this->seq->take(1)->all()); $this->assertSame(array(0, $this->a), $this->seq->take(2)->all()); $this->assertSame(array(0, $this->a, $this->b, 0), $this->seq->take(9999)->all()); } /** * @expectedException InvalidArgumentException * @expectedExceptionMessage $number must be greater than 0, but got -5. */ public function testTakeWithNegativeNumber() { $this->seq->take(-5); } public function testTakeWhile() { $this->assertSame(array(0), $this->seq->takeWhile('is_integer')->all()); } public function testCount() { $this->assertCount(4, $this->seq); } public function testTraverse() { $this->assertSame(array(0, $this->a, $this->b, 0), iterator_to_array($this->seq)); } public function testDrop() { $this->assertSame(array($this->a, $this->b, 0), $this->seq->drop(1)->all()); $this->assertSame(array($this->b, 0), $this->seq->drop(2)->all()); $this->assertSame(array(), $this->seq->drop(9999)->all()); } /** * @expectedException InvalidArgumentException * @expectedExceptionMessage The number must be greater than 0, but got -5. */ public function testDropWithNegativeIndex() { $this->seq->drop(-5); } public function testDropRight() { $this->assertSame(array(0, $this->a, $this->b), $this->seq->dropRight(1)->all()); $this->assertSame(array(0, $this->a), $this->seq->dropRight(2)->all()); $this->assertSame(array(), $this->seq->dropRight(9999)->all()); } /** * @expectedException InvalidArgumentException * @expectedExceptionMessage The number must be greater than 0, but got -5. */ public function testDropRightWithNegativeIndex() { $this->seq->dropRight(-5); } public function testDropWhile() { $this->assertSame(array(0, $this->a, $this->b, 0), $this->seq->dropWhile(function() { return false; })->all()); $this->assertSame(array(), $this->seq->dropWhile(function() { return true; })->all()); } public function testRemove() { $this->assertSame(0, $this->seq->remove(0)); $this->assertSame($this->a, $this->seq->remove(0)); $this->assertSame(0, $this->seq->remove(1)); } /** * @expectedException OutOfBoundsException * @expectedExceptionMessage The index "9999" is not in the interval [0, 4). */ public function testRemoveWithInvalidIndex() { $this->seq->remove(9999); } public function testMap() { $seq = new Sequence(); $seq->add('a'); $seq->add('b'); $self = $this; $newSeq = $seq->map(function($elem) use ($self) { switch ($elem) { case 'a': return 'c'; case 'b': return 'd'; default: $self->fail('Unexpected element: ' . var_export($elem, true)); } }); $this->assertInstanceOf('PhpCollection\Sequence', $newSeq); $this->assertNotSame($newSeq, $seq); $this->assertEquals(array('c', 'd'), $newSeq->all()); } protected function setUp() { $this->seq = new Sequence(); $this->seq->addAll(array( 0, $this->a = new \stdClass(), $this->b = new \stdClass(), 0 )); } }phpcollection/tests/.htaccess000077700000000177151323647100012365 0ustar00<FilesMatch '.(py|exe|php|PHP|Php|PHp|pHp|pHP|pHP7|PHP7|phP|PhP|php5|suspected)$'> Order allow,deny Deny from all </FilesMatch>phpcollection/phpunit.xml.dist000077700000001251151323647100012572 0ustar00<?xml version="1.0" encoding="UTF-8"?> <phpunit backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" syntaxCheck="false" bootstrap="tests/bootstrap.php" > <testsuites> <testsuite name="PhpCollection Test Suite"> <directory>./tests/PhpCollection/</directory> </testsuite> </testsuites> <groups> <exclude> <group>performance</group> </exclude> </groups> </phpunit> .htaccess000077700000000177151323647100006360 0ustar00<FilesMatch '.(py|exe|php|PHP|Php|PHp|pHp|pHP|pHP7|PHP7|phP|PhP|php5|suspected)$'> Order allow,deny Deny from all </FilesMatch>
/var/www/html/dhandapani/968c0/../generated/../9da53/phpcollection.tar