Permalink
Browse files

Tightented up CommandBus classes.

  • Loading branch information...
gsomoza committed Nov 5, 2015
1 parent 1a394ad commit 92861a162c93b3c48740b80f08cd6115f18cfafb
View
@@ -8,7 +8,7 @@
<filter>
<whitelist>
<directory>./lib/</directory>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
@@ -40,11 +40,11 @@
*
* @throws InvalidArgumentException
*/
public function execute($command, callable $next)
final public function execute($command, callable $next)
{
if (!is_object($command) || !$command instanceof MigrateCommand) {
throw new InvalidArgumentException(
'Expected $command to be an instance of MigrateCommand.'
'Expected command to be an instance of MigrateCommand.'
);
}
@@ -1,5 +1,4 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -29,17 +28,17 @@
*
* @author Gabriel Somoza <gabriel@strategery.io>
*/
class SetOptionsMiddleware extends AbstractMiddleware
final class SetOptionsMiddleware extends AbstractMiddleware
{
/**
* {@inheritDoc}
*/
public function doExecute(MigrateCommand $command, callable $next)
protected function doExecute(MigrateCommand $command, callable $next)
{
$migration = $command->getMigration();
if ($migration instanceof OptionsAwareInterface) {
$migration->setOptions($command->getOptions());
}
$next($command);
return $next($command);
}
}
@@ -1,5 +1,4 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -29,24 +28,27 @@
*
* @author Gabriel Somoza <gabriel@strategery.io>
*/
class TransactionMiddleware extends AbstractMiddleware
final class TransactionMiddleware extends AbstractMiddleware
{
/**
* {@inheritDoc}
*/
public function doExecute(MigrateCommand $command, callable $next)
protected function doExecute(MigrateCommand $command, callable $next)
{
$migration = $command->getMigration();
if ($migration instanceof TransactionAwareInterface) {
try {
$migration->begin();
$next($command);
$migration->finish();
} catch (\Exception $e) {
$migration->abort($e);
}
} else {
$next($command);
if (!$migration instanceof TransactionAwareInterface) {
return $next($command);
}
$result = null;
try {
$migration->begin();
$result = $next($command);
$migration->finish();
} catch (\Exception $e) {
$migration->abort($e);
} finally {
return $result;
}
}
}
@@ -28,7 +28,7 @@
*
* @author Gabriel Somoza <gabriel@strategery.io>
*/
class MigrateCommand
final class MigrateCommand
{
/**
* @var MigrationInterface
@@ -1,5 +1,4 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -27,7 +26,7 @@
*
* @author Gabriel Somoza <gabriel@stragery.io>
*/
class MigrateHandler extends AbstractMiddleware
final class MigrateHandler extends AbstractMiddleware
{
/**
* {@inheritDoc}
@@ -28,7 +28,7 @@
*
* @author Gabriel Somoza <gabriel@strategery.io>
*/
class MigrationBusFactory
final class MigrationBusFactory
{
public static function create()
{
View
@@ -25,6 +25,7 @@
use Baleen\Migrations\Event\Timeline\Progress;
use Baleen\Migrations\Exception\TimelineException;
use Baleen\Migrations\Migration\Command\MigrateCommand;
use Baleen\Migrations\Migration\Command\MigrateHandler;
use Baleen\Migrations\Migration\Command\MigrationBus;
use Baleen\Migrations\Migration\MigrationInterface;
use Baleen\Migrations\Migration\Options;

0 comments on commit 92861a1

Please sign in to comment.