mattjmattj/maybe 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mattjmattj/maybe

最新稳定版本:1.0.2

Composer 安装命令:

composer require mattjmattj/maybe

包简介

Fake objects for cleaner code and error handling

README 文档

README

Build Status Scrutinizer Code Quality Code Coverage

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
  • 点击次数: 6
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-2-Clause
  • 更新时间: 2015-03-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固