定制 gcdtech/usecases 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

gcdtech/usecases

最新稳定版本:2.0.0

Composer 安装命令:

composer require gcdtech/usecases

包简介

Base classes and interfaces for implementing the Use Case pattern along with entities and entity emitting iterators.

README 文档

README

Base classes and interfaces for implementing the Use Case pattern along with entities and entity emitting iterators.

UseCases

A UseCase is a single class, implementing one 'use case' of the application business logic. It co-ordinates the manipulation of application state to acheive it's purpose.

Key objectives

1. Be portable

By using only simple objects and primitive types as parameters and return types the use cases of your application are a permanent representation of your business logic and moving to a new language or framework should not require any significant recoding.

2. Integrate with framework as a plugin

Where use cases need to interact with external layers (for example to persist changes in state) this should always be acheived by wrapping the framework functionality as a service and injecting it as a dependancy. This ensures that the UseCases can always be moved to a new framework and the interop with the framework is easily assessed, rewritten and replaced with no changes to the UseCase code or tests.

3. Be testable

As UseCases only deal with pure and simple PHP classes they should be 100% testable and so TDD should be the favoured approach to development.

4. Do one thing

A UseCase should be focused on completing one business goal - for example creation of an invoice. Where the action requires a concert of other changes this can be acheived by calling other UserCases.

Signature of a UseCase

Generally a UseCase has a single method 'execute' which takes arguments and returns a response value. It may also have a constructor through which service dependancies are injected.

class DispatchOrderUseCase extends UseCase
{
  private $emailProvider;
  
  public function __construct(EmailProvider $email)
  {
    $this->emailProvider = $email;    
  }
  
  public function execute(Order $order)
  {
    // ... Do something to despatch the order
    $this->emailProvider->send(new DispatchEmail($order));
  }
}

Calling a UseCase

A UseCase should not be instantiated directly except in unit tests. In production code the static create() method ensure dependancies are injected using the DI container.

// Note no mention of the EmailProvider here...
DispatchOrderUseCase::create()->execute($order);

Entities

An entity is a simple POPO (Plain Old PHP Object) with no frills that represents the data passed into and out of UseCases. Generally an entity can be regarded as a model for a business object.

This library defines a base Entity class only to allow for basic type recognition (e.g. $arg instanceof Entity)

EntityEmittingIterator

ORMs generally support representing collections as iterable objects creating objects lazily as required. This is good practice to keep memory usage to the minimum possible. To represent a list we've provided an EntityEmittingIterator that extends the base Iterator PHP interface and can be used to classify parameter and return types.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2019-08-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固