1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace Db3v4l\Service; |
4
|
|
|
|
5
|
|
|
use Db3v4l\API\Interfaces\SqlExecutor\Forked\CommandExecutor as ForkedCommandExecutor; |
6
|
|
|
use Db3v4l\API\Interfaces\SqlExecutor\Forked\FileExecutor as ForkedFileExecutor; |
7
|
|
|
use Db3v4l\API\Interfaces\SqlExecutor\InProcess\CommandExecutor as InProcessCommandExecutor; |
8
|
|
|
use Db3v4l\API\Interfaces\SqlExecutor\InProcess\FileExecutor as InProcessFileExecutor; |
9
|
|
|
use Db3v4l\Core\SqlExecutor\Forked\NativeClient; |
10
|
|
|
use Db3v4l\Core\SqlExecutor\Forked\Doctrine as ForkedDoctrine; |
11
|
|
|
use Db3v4l\Core\SqlExecutor\Forked\PDO as ForkedPDO; |
12
|
|
|
use Db3v4l\Core\SqlExecutor\Forked\TimedExecutor as ForkedTimeExecutor; |
13
|
|
|
use Db3v4l\Core\SqlExecutor\InProcess\Doctrine as InProcessDoctrine; |
14
|
|
|
use Db3v4l\Core\SqlExecutor\InProcess\PDO as InProcessPDO; |
15
|
|
|
use Db3v4l\Core\SqlExecutor\InProcess\TimedExecutor as InProcessTimedExecutor; |
16
|
|
|
|
17
|
|
|
class SqlExecutorFactory |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
/** @var DatabaseConfigurationManager $dbConfigurationManager */ |
|
|
|
|
20
|
|
|
protected $dbConfigurationManager; |
21
|
|
|
|
22
|
|
|
public function __construct(DatabaseConfigurationManager $dbConfigurationManager) |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
$this->dbConfigurationManager = $dbConfigurationManager; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
|
|
|
|
28
|
|
|
* @param string $instanceName |
|
|
|
|
29
|
|
|
* @param array $databaseConnectionConfiguration |
|
|
|
|
30
|
|
|
* @param string $executionStrategy |
|
|
|
|
31
|
|
|
* @param bool $timed |
|
|
|
|
32
|
|
|
* @return ForkedCommandExecutor|ForkedFileExecutor |
|
|
|
|
33
|
|
|
* @throws \OutOfBoundsException |
|
|
|
|
34
|
|
|
*/ |
35
|
|
|
public function createForkedExecutor($instanceName, array $databaseConnectionConfiguration, $executionStrategy = NativeClient::EXECUTION_STRATEGY, $timed = true) |
36
|
|
|
{ |
37
|
|
|
switch ($executionStrategy) { |
38
|
|
|
case ForkedDoctrine::EXECUTION_STRATEGY: |
|
|
|
|
39
|
|
|
$executor = new ForkedDoctrine($databaseConnectionConfiguration); |
40
|
|
|
$executor->setInstanceName($instanceName); |
41
|
|
|
$executor->setDbConfigurationManager($this->dbConfigurationManager); |
42
|
|
|
break; |
43
|
|
|
case NativeClient::EXECUTION_STRATEGY: |
|
|
|
|
44
|
|
|
$executor = new NativeClient($databaseConnectionConfiguration); |
45
|
|
|
break; |
46
|
|
|
case ForkedPDO::EXECUTION_STRATEGY: |
|
|
|
|
47
|
|
|
$executor = new ForkedPDO($databaseConnectionConfiguration); |
48
|
|
|
$executor->setInstanceName($instanceName); |
49
|
|
|
$executor->setDbConfigurationManager($this->dbConfigurationManager); |
50
|
|
|
break; |
51
|
|
|
default: |
|
|
|
|
52
|
|
|
throw new \OutOfBoundsException("Unsupported execution strategy '$executionStrategy'"); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if ($timed) { |
56
|
|
|
$executor = new ForkedTimeExecutor($executor); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $executor; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
|
|
|
|
63
|
|
|
* @param string $instanceName |
|
|
|
|
64
|
|
|
* @param array $databaseConnectionConfiguration |
|
|
|
|
65
|
|
|
* @param string $executionStrategy |
|
|
|
|
66
|
|
|
* @param bool $timed |
|
|
|
|
67
|
|
|
* @return InProcessCommandExecutor|InProcessFileExecutor |
|
|
|
|
68
|
|
|
* @throws \OutOfBoundsException |
|
|
|
|
69
|
|
|
*/ |
70
|
|
|
public function createInProcessExecutor($instanceName, array $databaseConnectionConfiguration, $executionStrategy = 'Doctrine', $timed = true) |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
switch ($executionStrategy) { |
73
|
|
|
case InProcessDoctrine::EXECUTION_STRATEGY: |
|
|
|
|
74
|
|
|
$executor = new InProcessDoctrine($databaseConnectionConfiguration); |
75
|
|
|
break; |
76
|
|
|
case InProcessPDO::EXECUTION_STRATEGY: |
|
|
|
|
77
|
|
|
$executor = new InProcessPDO($databaseConnectionConfiguration); |
78
|
|
|
break; |
79
|
|
|
default: |
|
|
|
|
80
|
|
|
throw new \OutOfBoundsException("Unsupported execution strategy '$executionStrategy'"); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if ($timed) { |
84
|
|
|
$executor = new InprocessTimedExecutor($executor); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $executor; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|