yuriitatur/strategies
Composer 安装命令:
composer require yuriitatur/strategies
包简介
A simple package to update entities in certain declarative way
关键字:
README 文档
README
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
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-08