yrizos/bucket
最新稳定版本:0.2.0
Composer 安装命令:
composer require yrizos/bucket
包简介
A set of basic containers, and a more complicated one with onSet and onGet hooks.
README 文档
README
Bucket is a collection of container objects.
Basic containers
There are four basic container traits:
- 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:
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.
$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"
统计信息
- 总下载量: 95
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-02-24