1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Exception for the schema model. |
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 Schema_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 when a column doesn't exist. |
62
|
|
|
* |
63
|
|
|
* @param \PinkCrab\Table_Builder\Schema $schema |
64
|
|
|
* @param string $column |
65
|
|
|
* @return Schema_Exception |
66
|
|
|
*/ |
67
|
|
|
public static function column_not_exist( Schema $schema, string $column ): Schema_Exception { |
68
|
|
|
return new Schema_Exception( |
69
|
|
|
$schema, |
70
|
|
|
\sprintf( 'column with name %s is not currently defined', $column ), |
71
|
|
|
301 |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|