1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* The primary class for creating and dropping tables. |
7
|
|
|
* |
8
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
9
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
10
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
11
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
12
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
13
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
14
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
15
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
16
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
17
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
18
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
19
|
|
|
* |
20
|
|
|
* @since 0.3.0 |
21
|
|
|
* @author Glynn Quelch <[email protected]> |
22
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
23
|
|
|
* @package PinkCrab\Table_Builder |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace PinkCrab\Table_Builder; |
27
|
|
|
|
28
|
|
|
use PinkCrab\Table_Builder\Engines\Engine; |
29
|
|
|
use PinkCrab\Table_Builder\Schema; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
class Builder { |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The engine used to create the tables |
36
|
|
|
* |
37
|
|
|
* @var Engine |
38
|
|
|
*/ |
39
|
|
|
protected $engine; |
40
|
|
|
|
41
|
|
|
public function __construct( Engine $engine, ?callable $engine_config = null ) { |
42
|
|
|
$this->engine = $engine_config |
43
|
|
|
? $engine_config( $engine ) |
44
|
|
|
: $engine; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Creates the table |
49
|
|
|
* |
50
|
|
|
* @param Schema $schema |
51
|
|
|
* @return bool |
52
|
|
|
*/ |
53
|
|
|
public function create_table( Schema $schema ): bool { |
54
|
|
|
return $this->engine->create_table( $schema ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Drop a table |
59
|
|
|
* |
60
|
|
|
* @param Schema $schema |
61
|
|
|
* @return bool |
62
|
|
|
*/ |
63
|
|
|
public function drop_table( Schema $schema ): bool { |
64
|
|
|
return $this->engine->drop_table( $schema ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Access to the builders engine. |
69
|
|
|
* |
70
|
|
|
* @return Engine |
71
|
|
|
*/ |
72
|
|
|
public function get_engine(): Engine { |
73
|
|
|
return $this->engine; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|