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

GitHub 信息

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

其他信息

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