Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| DatabaseTable | |
0.00% |
0 / 11 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| addColumns | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| setName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __get | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace UserFrosting; |
| 4 | |
| 5 | /** |
| 6 | * DatabaseTable Class |
| 7 | * |
| 8 | * A data class representing a database table. Specifies the table name and whitelisted columns. |
| 9 | * |
| 10 | */ |
| 11 | class DatabaseTable implements DatabaseTableInterface { |
| 12 | |
| 13 | /** |
| 14 | * @var string The name of the table. |
| 15 | */ |
| 16 | protected $_name; |
| 17 | |
| 18 | /** |
| 19 | * @var array[string] A list of the allowed columns for this table. The `id` column is already assumed. |
| 20 | */ |
| 21 | protected $_columns; |
| 22 | |
| 23 | public function __construct($name, $columns = []){ |
| 24 | $this->_name = $name; |
| 25 | $this->_columns = $columns; |
| 26 | } |
| 27 | |
| 28 | public function addColumns() { |
| 29 | $new_columns = func_get_args(); |
| 30 | $this->_columns = $this->_columns + $new_columns; |
| 31 | return $this; |
| 32 | } |
| 33 | |
| 34 | public function setName($name){ |
| 35 | $this->_name = $name; |
| 36 | } |
| 37 | |
| 38 | public function __get($name){ |
| 39 | if ($name == "name"){ |
| 40 | return $this->_name; |
| 41 | } else if ($name == "columns"){ |
| 42 | return $this->_columns; |
| 43 | } else { |
| 44 | throw new \Exception("The value '$name' does not exist in the table configuration object."); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | } |