1: <?php
2: /**
3: * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4: * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5: *
6: * Licensed under The MIT License
7: * For full copyright and license information, please see the LICENSE.txt
8: * Redistributions of files must retain the above copyright notice.
9: *
10: * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
11: * @link http://cakephp.org CakePHP(tm) Project
12: * @since 3.5.0
13: * @license http://www.opensource.org/licenses/mit-license.php MIT License
14: */
15: namespace Cake\Datasource;
16:
17: /**
18: * An interface used by TableSchema objects.
19: */
20: interface SchemaInterface
21: {
22: /**
23: * Get the name of the table.
24: *
25: * @return string
26: */
27: public function name();
28:
29: /**
30: * Add a column to the table.
31: *
32: * ### Attributes
33: *
34: * Columns can have several attributes:
35: *
36: * - `type` The type of the column. This should be
37: * one of CakePHP's abstract types.
38: * - `length` The length of the column.
39: * - `precision` The number of decimal places to store
40: * for float and decimal types.
41: * - `default` The default value of the column.
42: * - `null` Whether or not the column can hold nulls.
43: * - `fixed` Whether or not the column is a fixed length column.
44: * This is only present/valid with string columns.
45: * - `unsigned` Whether or not the column is an unsigned column.
46: * This is only present/valid for integer, decimal, float columns.
47: *
48: * In addition to the above keys, the following keys are
49: * implemented in some database dialects, but not all:
50: *
51: * - `comment` The comment for the column.
52: *
53: * @param string $name The name of the column
54: * @param array|string $attrs The attributes for the column.
55: * @return $this
56: */
57: public function addColumn($name, $attrs);
58:
59: /**
60: * Get column data in the table.
61: *
62: * @param string $name The column name.
63: * @return array|null Column data or null.
64: */
65: public function getColumn($name);
66:
67: /**
68: * Returns true if a column exists in the schema.
69: *
70: * @param string $name Column name.
71: * @return bool
72: */
73: public function hasColumn($name);
74:
75: /**
76: * Remove a column from the table schema.
77: *
78: * If the column is not defined in the table, no error will be raised.
79: *
80: * @param string $name The name of the column
81: * @return $this
82: */
83: public function removeColumn($name);
84:
85: /**
86: * Get the column names in the table.
87: *
88: * @return string[]
89: */
90: public function columns();
91:
92: /**
93: * Returns column type or null if a column does not exist.
94: *
95: * @param string $name The column to get the type of.
96: * @return string|null
97: */
98: public function getColumnType($name);
99:
100: /**
101: * Sets the type of a column.
102: *
103: * @param string $name The column to set the type of.
104: * @param string $type The type to set the column to.
105: * @return $this
106: */
107: public function setColumnType($name, $type);
108:
109: /**
110: * Returns the base type name for the provided column.
111: * This represent the database type a more complex class is
112: * based upon.
113: *
114: * @param string $column The column name to get the base type from
115: * @return string|null The base type name
116: */
117: public function baseColumnType($column);
118:
119: /**
120: * Check whether or not a field is nullable
121: *
122: * Missing columns are nullable.
123: *
124: * @param string $name The column to get the type of.
125: * @return bool Whether or not the field is nullable.
126: */
127: public function isNullable($name);
128:
129: /**
130: * Returns an array where the keys are the column names in the schema
131: * and the values the database type they have.
132: *
133: * @return array
134: */
135: public function typeMap();
136:
137: /**
138: * Get a hash of columns and their default values.
139: *
140: * @return array
141: */
142: public function defaultValues();
143:
144: /**
145: * Sets the options for a table.
146: *
147: * Table options allow you to set platform specific table level options.
148: * For example the engine type in MySQL.
149: *
150: * @param array $options The options to set, or null to read options.
151: * @return $this
152: */
153: public function setOptions($options);
154:
155: /**
156: * Gets the options for a table.
157: *
158: * Table options allow you to set platform specific table level options.
159: * For example the engine type in MySQL.
160: *
161: * @return array An array of options.
162: */
163: public function getOptions();
164: }
165: