|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Repositories\AbstractSqlStatementRepository |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/techdivision/import |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Repositories; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Abstract repository class for the SQL statements to use. |
|
25
|
|
|
* |
|
26
|
|
|
* @author Tim Wagner <[email protected]> |
|
27
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
29
|
|
|
* @link https://github.com/techdivision/import |
|
30
|
|
|
* @link http://www.techdivision.com |
|
31
|
|
|
*/ |
|
32
|
|
|
abstract class AbstractSqlStatementRepository implements SqlStatementRepositoryInterface |
|
33
|
|
|
{ |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* The initializes SQL statements. |
|
37
|
|
|
* |
|
38
|
|
|
* @var array |
|
39
|
|
|
*/ |
|
40
|
|
|
private $preparedStatements = array(); |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* The array with the compiler instances. |
|
44
|
|
|
* |
|
45
|
|
|
* @var \IteratorAggregate<\TechDivision\Import\Utils\SqlCompilerInterface> |
|
46
|
|
|
*/ |
|
47
|
|
|
private $compilers = array(); |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Initializes the SQL statement repository with the primary key and table prefix utility. |
|
51
|
|
|
* |
|
52
|
|
|
* @param \IteratorAggregate<\TechDivision\Import\Utils\SqlCompilerInterface> $compilers The array with the compiler instances |
|
|
|
|
|
|
53
|
|
|
*/ |
|
54
|
2 |
|
public function __construct(\IteratorAggregate $compilers) |
|
55
|
|
|
{ |
|
56
|
2 |
|
$this->compilers = $compilers; |
|
|
|
|
|
|
57
|
2 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Returns the SQL statement with the passed ID. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $id The ID of the SQL statement to return |
|
63
|
|
|
* |
|
64
|
|
|
* @return string The SQL statement |
|
65
|
|
|
* @throws \Exception Is thrown, if the SQL statement with the passed key cannot be found |
|
66
|
|
|
*/ |
|
67
|
2 |
|
public function load($id) |
|
68
|
|
|
{ |
|
69
|
|
|
|
|
70
|
|
|
// try to find the SQL statement with the passed key |
|
71
|
2 |
|
if (isset($this->preparedStatements[$id])) { |
|
72
|
1 |
|
return $this->preparedStatements[$id]; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
// throw an exception if NOT available |
|
76
|
1 |
|
throw new \Exception(sprintf('Can\'t find SQL statement with ID %s', $id)); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Compiles the passed SQL statements. |
|
81
|
|
|
* |
|
82
|
|
|
* @param array $statements The SQL statements to compile |
|
83
|
|
|
* |
|
84
|
|
|
* @return void |
|
85
|
|
|
*/ |
|
86
|
2 |
|
protected function compile(array $statements) |
|
87
|
|
|
{ |
|
88
|
|
|
|
|
89
|
|
|
// iterate over all statements and compile them |
|
90
|
2 |
|
foreach ($statements as $key => $statement) { |
|
91
|
|
|
// compile the statement |
|
92
|
2 |
|
foreach ($this->compilers as $compiler) { |
|
93
|
2 |
|
$statement = $compiler->compile($statement); |
|
94
|
|
|
} |
|
95
|
|
|
// add the comiled statemnent to the list |
|
96
|
2 |
|
$this->preparedStatements[$key] = $statement; |
|
97
|
|
|
} |
|
98
|
2 |
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.