承接 jeroen/generic-decorator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

jeroen/generic-decorator

Composer 安装命令:

composer require jeroen/generic-decorator

包简介

Builder for generic and type safe decorators

README 文档

README

Build Status Latest Stable Version Download count

A builder for generic and type safe PHP decorators.

Usage

This library provides the DecoratorBuilder class, which follows the Builder pattern, and thus is similar in use as PHPUnit's MockBuilder interface.

You construct a new builder by calling DecoratorBuilder::newBuilder and passing in the object you want to decorate. Then you can call withBefore and withAfter, to define the decorated behaviour. Finally you call newDecorator and get the decorated instance.

public function __construct() {
    $this->repository = new DoctrineKittenRepository( /* ... */ );
    $this->stopWatch = new Stopwatch();
}

public function newProfilingKittenRepository(): KittenRepository {
    return DecoratorBuilder::newBuilder( $this->repository )
    	->withBefore( function() {
    		$this->stopWatch->start( 'KittenRepository' );
    	} )
    	->withAfter( function() {
			$this->stopWatch->stop( 'KittenRepository' );
		} )
		->newDecorator();
}

The callable provided to withBefore and withAfter receives all arguments the decorated method receives.

->withBefore( function() {
	$this->logger->alert( 'KittenRepository', [ 'arguments' => func_get_args() ] );
} )

Missing features / roadmap

  • Allow decorating generated decorators (this will fatal error at present)
  • Support try-catch, ie for logging decorators
  • Provide a way to get the name of the calling method (anyone knows how to do that without crazy debug_backtrace hacks?)
  • Test presence of private and protected methods
  • Test final class
  • Test exceptions
  • Test internal calls to public methods

Release notes

0.1.2 (2017-02-06)

  • Made installable with PHPUnit Mock Objects 4.x

0.1.1 (2016-08-16)

  • Decorating classes with required constructor parameters now works

0.1.0 (2016-07-29)

  • Initial release

统计信息

  • 总下载量: 8.58k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 4
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2016-07-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固