Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| UFDatabase | |
0.00% |
0 / 12 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
| getTable | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| setTable | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setTableName | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| addTableColumns | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace UserFrosting; |
| 4 | |
| 5 | /** |
| 6 | * UFDatabase Class |
| 7 | * |
| 8 | * Represents the UserFrosting database configuration. |
| 9 | * This class acts as a "registry" of sorts, allowing all data model classes to access information about your database, |
| 10 | * such as table names and whitelisted columns. Each table in your model shall be represented by a DatabaseTable object. |
| 11 | * |
| 12 | */ |
| 13 | abstract class UFDatabase { |
| 14 | |
| 15 | /** |
| 16 | * @var Slim The Slim app, containing configuration info |
| 17 | */ |
| 18 | public static $app; |
| 19 | |
| 20 | /** |
| 21 | * @var array[DatabaseTable] An array of DatabaseTable objects representing the configuration of the database tables. |
| 22 | */ |
| 23 | protected static $tables; |
| 24 | |
| 25 | public static function getTable($id){ |
| 26 | if (isset(static::$tables[$id])) |
| 27 | return static::$tables[$id]; |
| 28 | else |
| 29 | throw new \Exception("There is no table with id '$id'."); |
| 30 | } |
| 31 | |
| 32 | public static function setTable($id, $table){ |
| 33 | static::$tables[$id] = $table; |
| 34 | } |
| 35 | |
| 36 | public static function setTableName($id, $name){ |
| 37 | if (isset(static::$tables[$id])) { |
| 38 | $columns = array_slice(func_get_args(), 1); |
| 39 | call_user_func_array(static::$tables[$id], $columns); |
| 40 | } else |
| 41 | throw new \Exception("There is no table with id '$id'."); |
| 42 | } |
| 43 | |
| 44 | public static function addTableColumns($id){ |
| 45 | if (isset(static::$tables[$id])) { |
| 46 | $columns = array_slice(func_get_args(), 1); |
| 47 | call_user_func_array([static::$tables[$id], "addColumns"], $columns); |
| 48 | } else |
| 49 | throw new \Exception("There is no table with id '$id'."); |
| 50 | } |
| 51 | |
| 52 | } |