icecave / reverb
该软件包已被废弃,不再维护。未建议替代软件包。
Doctrine ORM 的交易执行器。
0.1.0
2014-08-26 09:26 UTC
Requires
- php: >=5.5
- doctrine/orm: ~2
Requires (Dev)
- icecave/archer: ~1
Suggests
- eloquent/asplode: Drop-in exception-based error handling.
This package is not auto-updated.
Last update: 2019-05-28 04:15:41 UTC
README
Reverb 是一个 PHP 库,用于执行带有 Doctrine 对象关系映射器 (ORM) 的可重试事务。
- 通过 Composer 包 icecave/reverb 安装
- 阅读 API 文档
概述
Reverb 提供与 Doctrine 的 EntityManager::transactional()
方法类似的功能,但在异常处理方面有两个主要区别
以下任一条件为真时,异常被视为 '重试安全'
- 它是 Doctrine 的 OptimisticLockException 或 PessimisticLockException 的实例
- 它实现了 RetrySafeExceptionInterface 接口
- 提供了一个自定义的重试安全谓词,并且当传递给异常时返回
true
示例
/** * This is an example of a custom 'retry safe predicate'. * * It instructs the transaction executor to retry transactions in the event that * MyFancyException is thrown. * * This same functionality could be accomplished by having MyFancyException * implement Icecave\Reverb\RetrySafeException. */ $isRetrySafe = function (Exception $e) { return $e instanceof MyFancyException; }; $executor = new Icecave\Reverb\TransactionExecutor($entityManager, $isRetrySafe); $result = $executor( /** * This is the transaction body. * * This function may be called multiple times in order to retry the * transaction. Each time it is passed the entity manager along with the * number of attempts remaining, not including this one. */ function ($entityManager, $attemptsRemaining) { // Perform transactional work with $entityManager return '<result>'; } ); assert($result === '<result>')
联系我们
- 关注 @IcecaveStudios 在 Twitter 上
- 访问 Icecave Studios 网站
- 加入
#icecave
在 irc.freenode.net