定制 yuriitatur/strategies 二次开发

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

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

yuriitatur/strategies

Composer 安装命令:

composer require yuriitatur/strategies

包简介

A simple package to update entities in certain declarative way

README 文档

README

Quality Gate Status Coverage

Simple entity strategy package

Installation

Composer:

composer require yuriitatur/strategies

Usage

// $manager instanceOf ChangesManager

$saga = $manager->initialize($entity); // initialize changes listening
$entity->setNewValue(123); // modify data
$saga->apply(); //save changes| do smth else

This will get all the possible strategies and apply them.

Strategy

The strategy is an object of a class implementing StrategyInterface. It has only one method - apply which applies it. You can add conditions to it by applying PreCondition attribute and specify the condition under what this strategy may be applied. After all preconditions are met, the strategy is applied. You can manipulate it by specifying middlewares BeforeApply, AfterApply and OverApply, which, as you can guess, are applied before, after or have full control around the apply method.


#[PreCondition(RequiresEntityId::class)]
#[PreCondition(HasChanged::class, ['status'])]
#[BeforeApply(SaveEntity::class)]
class ShipOrder implements StrategyInterface
{
    public function apply(Entity $order) 
    {
        event(new OrderShipped($order));
    }
}

Testing

composer test

License

This code is under MIT license, read more in the LICENSE file.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-08