1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of graze/sprout. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2017 Nature Delivered Ltd. <https://www.graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/graze/sprout/blob/master/LICENSE.md |
11
|
|
|
* @link https://github.com/graze/sprout |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Graze\Sprout\Chop; |
15
|
|
|
|
16
|
|
|
use Graze\ParallelProcess\Pool; |
17
|
|
|
use Graze\Sprout\Chop\Mysql\MysqlTableChopper; |
18
|
|
|
use Graze\Sprout\Config\ConnectionConfigInterface; |
19
|
|
|
use InvalidArgumentException; |
20
|
|
|
use Psr\Log\LoggerAwareInterface; |
21
|
|
|
use Psr\Log\LoggerAwareTrait; |
22
|
|
|
|
23
|
|
|
class TableChopperFactory implements LoggerAwareInterface |
24
|
|
|
{ |
25
|
|
|
use LoggerAwareTrait; |
26
|
|
|
|
27
|
|
|
/** @var Pool */ |
28
|
|
|
private $processPool; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* TableDumperFactory constructor. |
32
|
|
|
* |
33
|
|
|
* @param Pool $processPool |
34
|
|
|
* |
35
|
|
|
* @internal param OutputInterface $output |
36
|
|
|
*/ |
37
|
3 |
|
public function __construct(Pool $processPool) |
38
|
|
|
{ |
39
|
3 |
|
$this->processPool = $processPool; |
40
|
3 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param ConnectionConfigInterface $connection |
44
|
|
|
* |
45
|
|
|
* @return TableChopperInterface |
46
|
|
|
*/ |
47
|
3 |
|
public function getChopper(ConnectionConfigInterface $connection): TableChopperInterface |
48
|
|
|
{ |
49
|
3 |
|
$driver = $connection->getDriver(); |
50
|
|
|
|
51
|
|
|
switch ($driver) { |
52
|
3 |
|
case 'mysql': |
53
|
2 |
|
if ($this->logger) { |
54
|
1 |
|
$this->logger->debug( |
55
|
1 |
|
"getChopper: using mysql chopper for driver: {$driver}", |
56
|
1 |
|
['driver' => $driver] |
57
|
|
|
); |
58
|
|
|
} |
59
|
2 |
|
return new MysqlTableChopper($this->processPool, $connection); |
60
|
|
|
default: |
61
|
1 |
|
throw new InvalidArgumentException("getChopper: no chopper found for driver: `{$driver}`"); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|