Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mnapoli
Last active December 16, 2015 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnapoli/5466043 to your computer and use it in GitHub Desktop.
Save mnapoli/5466043 to your computer and use it in GitHub Desktop.
Collection and Map interface
<?php
/**
* In this example, a collection is a map of values indexed by a key (numeric or string)
*/
interface Collection extends Countable, IteratorAggregate, ArrayAccess
{
function add($value);
function set($key, $value);
function get($key);
function contains($key);
function containsValue($value);
function remove($key);
function removeValue($value);
function clear();
function count();
function isEmpty();
function filter(Closure $p);
function forAll(Closure $p);
function map(Closure $func);
function toArray();
}
<?php
/**
* In this example, a Collection is a list of values (not indexed or mapped).
*/
interface Collection extends Countable, IteratorAggregate, ArrayAccess
{
function add($value);
function addAll(Collection $collection);
function contains($value);
function containsAll(Collection $collection);
function remove($value);
function removeAll(Collection $collection);
function clear();
function count();
function isEmpty();
function filter(Closure $p);
function forAll(Closure $p);
function map(Closure $func);
function toArray();
}
/**
* A map is a list of values indexed by a key
*/
interface Map extends Countable, IteratorAggregate, ArrayAccess
{
function set($key, $value);
function get($key);
function getKeys();
function getValues();
function contains($key);
function containsValue($value);
function remove($key);
function clear();
function count();
function isEmpty();
function set($key, $value);
function filter(Closure $p);
function forAll(Closure $p);
function map(Closure $func);
function toArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment