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: /**
24: * Get the name of the table.
25: *
26: * @return string
27: */
28: public function name();
29:
30: /**
31: * Add a column to the table.
32: *
33: * ### Attributes
34: *
35: * Columns can have several attributes:
36: *
37: * - `type` The type of the column. This should be
38: * one of CakePHP's abstract types.
39: * - `length` The length of the column.
40: * - `precision` The number of decimal places to store
41: * for float and decimal types.
42: * - `default` The default value of the column.
43: * - `null` Whether or not the column can hold nulls.
44: * - `fixed` Whether or not the column is a fixed length column.
45: * This is only present/valid with string columns.
46: * - `unsigned` Whether or not the column is an unsigned column.
47: * This is only present/valid for integer, decimal, float columns.
48: *
49: * In addition to the above keys, the following keys are
50: * implemented in some database dialects, but not all:
51: *
52: * - `comment` The comment for the column.
53: *
54: * @param string $name The name of the column
55: * @param array|string $attrs The attributes for the column.
56: * @return $this
57: */
58: public function addColumn($name, $attrs);
59:
60: /**
61: * Get column data in the table.
62: *
63: * @param string $name The column name.
64: * @return array|null Column data or null.
65: */
66: public function getColumn($name);
67:
68: /**
69: * Returns true if a column exists in the schema.
70: *
71: * @param string $name Column name.
72: * @return bool
73: */
74: public function hasColumn($name);
75:
76: /**
77: * Remove a column from the table schema.
78: *
79: * If the column is not defined in the table, no error will be raised.
80: *
81: * @param string $name The name of the column
82: * @return $this
83: */
84: public function removeColumn($name);
85:
86: /**
87: * Get the column names in the table.
88: *
89: * @return string[]
90: */
91: public function columns();
92:
93: /**
94: * Returns column type or null if a column does not exist.
95: *
96: * @param string $name The column to get the type of.
97: * @return string|null
98: */
99: public function getColumnType($name);
100:
101: /**
102: * Sets the type of a column.
103: *
104: * @param string $name The column to set the type of.
105: * @param string $type The type to set the column to.
106: * @return $this
107: */
108: public function setColumnType($name, $type);
109:
110: /**
111: * Returns the base type name for the provided column.
112: * This represent the database type a more complex class is
113: * based upon.
114: *
115: * @param string $column The column name to get the base type from
116: * @return string|null The base type name
117: */
118: public function baseColumnType($column);
119:
120: /**
121: * Check whether or not a field is nullable
122: *
123: * Missing columns are nullable.
124: *
125: * @param string $name The column to get the type of.
126: * @return bool Whether or not the field is nullable.
127: */
128: public function isNullable($name);
129:
130: /**
131: * Returns an array where the keys are the column names in the schema
132: * and the values the database type they have.
133: *
134: * @return array
135: */
136: public function typeMap();
137:
138: /**
139: * Get a hash of columns and their default values.
140: *
141: * @return array
142: */
143: public function defaultValues();
144:
145: /**
146: * Sets the options for a table.
147: *
148: * Table options allow you to set platform specific table level options.
149: * For example the engine type in MySQL.
150: *
151: * @param array $options The options to set, or null to read options.
152: * @return $this
153: */
154: public function setOptions($options);
155:
156: /**
157: * Gets the options for a table.
158: *
159: * Table options allow you to set platform specific table level options.
160: * For example the engine type in MySQL.
161: *
162: * @return array An array of options.
163: */
164: public function getOptions();
165: }
166: