1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <https://github.com/baleen/migrations>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Baleen\Migrations\Service\MigrationBus; |
21
|
|
|
|
22
|
|
|
use Baleen\Migrations\Exception\MigrationBusException; |
23
|
|
|
use Baleen\Migrations\Service\MigrationBus\Middleware\SetOptionsMiddleware; |
24
|
|
|
use Baleen\Migrations\Service\MigrationBus\Middleware\TransactionMiddleware; |
25
|
|
|
use League\Tactician\CommandBus; |
26
|
|
|
|
27
|
|
|
final class MigrationBus extends CommandBus implements MigrationBusInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @inheritdoc |
31
|
|
|
*/ |
32
|
122 |
|
public function __construct(array $middleware) |
33
|
|
|
{ |
34
|
122 |
|
$foundHandler = false; |
35
|
122 |
|
foreach ($middleware as $object) { |
36
|
121 |
|
if ($object instanceof MigrateHandler) { |
37
|
121 |
|
$foundHandler = true; |
38
|
121 |
|
break; |
39
|
|
|
} |
40
|
122 |
|
} |
41
|
122 |
|
if (!$foundHandler) { |
42
|
1 |
|
throw new MigrationBusException(sprintf( |
43
|
1 |
|
'MigrationBus must have at least one instance of "%s"', |
44
|
|
|
MigrateHandler::class |
45
|
1 |
|
)); |
46
|
|
|
} |
47
|
121 |
|
parent::__construct($middleware); |
48
|
121 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* factory |
52
|
|
|
* @return MigrationBus |
53
|
|
|
*/ |
54
|
121 |
|
public static function createDefaultBus() |
55
|
|
|
{ |
56
|
121 |
|
return new MigrationBus(static::getDefaultMiddleWare()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* getDefaultMiddleWare |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
122 |
|
public static function getDefaultMiddleWare() |
64
|
|
|
{ |
65
|
|
|
return [ |
66
|
122 |
|
new SetOptionsMiddleware(), |
67
|
122 |
|
new TransactionMiddleware(), |
68
|
122 |
|
new MigrateHandler(), |
69
|
122 |
|
]; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|