mattjmattj/maybe
最新稳定版本:1.0.2
Composer 安装命令:
composer require mattjmattj/maybe
包简介
Fake objects for cleaner code and error handling
README 文档
README
Maybe wraps a class and provides a way to abstract away error handling when dealing with undefined instances. It might help implement feature switches, dev/prod environments switches, etc.
Installation
with composer
composer.phar require mattjmattj/maybe ~1.0
Basic usage
use Maybe\Maybe; /* * Create a Maybe instance for the desired class or interface. */ $maybe = new Maybe('Some\Class'); /* * Wrap some object that you don't know much about : * might be null or an actual instance of Some\Class. */ $wrapped = $maybe->wrap($someContainer->getSomeClassInstance()); /* * Call whatever you want on the wrapped object without having * to worry about whether $someContainer->getSomeClassInstance() * return something or not. */ $wrapped->doSomeInterestingThing(); /* * You can also call a method at a deeper level. Maybe will wrap returned types * if it finds proper @return annotations */ $wrapped->getSomeService()->doSomeJob();
Example
Examples are provided in the "example" folder:
- Log : An example of how to use Maybe with an IoC container to wrap a "log" feature and write code with no worries.
- Email : An example of how to use Maybe to create fake objects from interfaces only. An example of "deep" wrapping.
Warning
Not every kind of object should be wrapped. Typically you will want to wrap classes that provide logs, debug, cache, events, etc. You don't want to wrap "useful" classes that actually alter the logic of your code.
License
Maybe is licensed under BSD-2-Clause license.
统计信息
- 总下载量: 52
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-2-Clause
- 更新时间: 2015-03-18