for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of the Borobudur-Cqrs package.
* (c) 2016 Hexacodelabs <http://hexacodelabs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Borobudur\Cqrs;
use Borobudur\Cqrs\ReadModel\Storage\TransactionalInterface;
use Closure;
* @author Iqbal Maulana <[email protected]>
* @created 8/2/16
class UnitOfWorkTransaction implements TransactionalInterface
{
* @var TransactionalInterface[]
private $handlers = array();
* Constructor.
* @param TransactionalInterface[] $handlers
public function __construct(array $handlers = array())
foreach ($handlers as $handler) {
$this->add($handler);
}
* Add transactional handler.
* @param TransactionalInterface $handler
public function add(TransactionalInterface $handler)
$this->handlers[] = $handler;
* Begin transaction
public function beginTransaction()
$this->execute(
function (TransactionalInterface $handler) {
$handler->beginTransaction();
);
* Rollback transaction
public function rollback()
$handler->rollback();
* Commit transaction.
public function commit()
$handler->commit();
* @param Closure $closure
protected function execute(Closure $closure)
foreach ($this->handlers as $handler) {
$closure($handler);