|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Exception for the table builder. |
|
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 1.1.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\Exception; |
|
27
|
|
|
|
|
28
|
|
|
use Exception; |
|
29
|
|
|
use Throwable; |
|
30
|
|
|
use PinkCrab\Table_Builder\Schema; |
|
31
|
|
|
|
|
32
|
|
|
class Engine_Exception extends Exception { |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* The table schema. |
|
36
|
|
|
* |
|
37
|
|
|
* @var Schema|null |
|
38
|
|
|
*/ |
|
39
|
|
|
private $schema; |
|
40
|
|
|
|
|
41
|
|
|
public function __construct( |
|
42
|
|
|
?Schema $schema = null, |
|
43
|
|
|
string $message = '', |
|
44
|
|
|
int $code = 0, |
|
45
|
|
|
?Throwable $previous = null |
|
46
|
|
|
) { |
|
47
|
|
|
$this->schema = $schema; |
|
48
|
|
|
parent::__construct( $message, $code, $previous ); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Get the table schema. |
|
53
|
|
|
* |
|
54
|
|
|
* @return Schema|null |
|
55
|
|
|
*/ |
|
56
|
|
|
public function get_schema(): ?Schema { |
|
57
|
|
|
return $this->schema; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Throw an exception for errors when creating table. |
|
62
|
|
|
* |
|
63
|
|
|
* @param \PinkCrab\Table_Builder\Schema $schema |
|
64
|
|
|
* @param string $error |
|
65
|
|
|
* @return Engine_Exception |
|
66
|
|
|
* @code 101 |
|
67
|
|
|
*/ |
|
68
|
|
|
public static function create_table( Schema $schema, string $error ): Engine_Exception { |
|
69
|
|
|
return new self( $schema, $error, 101 ); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Throw an exception for errors when dropping a table. |
|
74
|
|
|
* |
|
75
|
|
|
* @param \PinkCrab\Table_Builder\Schema $schema |
|
76
|
|
|
* @param string $error |
|
77
|
|
|
* @return Engine_Exception |
|
78
|
|
|
* @code 102 |
|
79
|
|
|
*/ |
|
80
|
|
|
public static function drop_table( Schema $schema, string $error ): Engine_Exception { |
|
81
|
|
|
return new self( $schema, $error, 102 ); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|