2017 © Pedro Peláez
 

library bucket

A set of basic containers, and a more complicated one with onSet and onGet hooks.

image

yrizos/bucket

A set of basic containers, and a more complicated one with onSet and onGet hooks.

  • Tuesday, July 22, 2014
  • by yrizos
  • Repository
  • 1 Watchers
  • 5 Stars
  • 86 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Bucket

Bucket is a collection of container objects., (*1)

Basic containers

There are four basic container traits:, (*2)

  • ContainerTrait: implements \Countable, \IteratorAggregate
  • ArrayContainerTrait: adds \ArrayAccess to the mix
  • MagicContainerTrait: if you prefer magic getter & setters to \ArrayAccess
  • MagicArrayContainerTrait: the name is revealing, isn't it?

You can either attach the traits to your own classes, or use the concrete classes provided. Here's a quick example:, (*3)

class MyContainer implements Bucket\Container\MagicArrayContainerInterface
{
    use Bucket\Container\MagicArrayContainerTrait;
}

$myContainer        = new MyContainer();
$myContainer->label = "hello world";

echo $myContainer["label"];

Bucket

Bucket is a bit more interesting, adding hooks to the mix., (*4)

$bucket = new Bucket\Bucket();

$bucket->onGet("name", function ($value) {
    return trim($value);
});

$bucket->onSet("email", function ($value) {

    if (!filter_var($value, FILTER_VALIDATE_EMAIL))
        throw new  \InvalidArgumentException();

    return filter_var($value, FILTER_SANITIZE_EMAIL);
});


$bucket->name = "    Yannis    ";
var_dump($bucket->name); // string 'Yannis' (length=6)

$bucket->email = 42; // will fail

Setup

require: "yrizos/bucket": "dev-master"

Build Status, (*5)

The Versions

22/07 2014

dev-master

9999999-dev https://github.com/yrizos/bucket

A set of basic containers, and a more complicated one with onSet and onGet hooks.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

22/07 2014

0.2.0

0.2.0.0 https://github.com/yrizos/bucket

A set of basic containers, and a more complicated one with onSet and onGet hooks.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

01/03 2013

0.1.0

0.1.0.0

A set of basic containers, and a more complicated one with onSet and onGet hooks.

  Sources   Download

MIT

The Requires

  • php >=5.3.0