1 | <?php |
||
21 | class BaseModel implements InterfaceBaseClass |
||
22 | { |
||
23 | protected $databaseModel; // Private variable that contains instance of database |
||
24 | protected $tableName; // Class variable holding class name pluralized |
||
25 | protected $properties = []; // Properties will later contain key, value pairs from the magic setter, getter methods |
||
26 | |||
27 | use Inflector; // Inject the inflector trait |
||
28 | |||
29 | public function __construct() |
||
37 | |||
38 | /** |
||
39 | * The magic getter method |
||
40 | * @params key |
||
41 | * @return array key |
||
42 | */ |
||
43 | public function __get($key) |
||
48 | |||
49 | /** |
||
50 | * The magic setter method |
||
51 | * @params property, key |
||
52 | * @return array associative array properties |
||
53 | */ |
||
54 | public function __set($property, $value) |
||
59 | |||
60 | /** |
||
61 | * This method gets all the record from a particular table |
||
62 | * @params void |
||
63 | * @return associative array |
||
64 | * @throws NoRecordFoundException |
||
65 | */ |
||
66 | public static function getAll() |
||
78 | |||
79 | /** |
||
80 | * This method create or update record in a database table |
||
81 | * @params void |
||
82 | * @return bool true or false; |
||
83 | * @throws EmptyArrayException |
||
84 | * @throws NoRecordInsertionException |
||
85 | * @throws NoRecordUpdateException |
||
86 | */ |
||
87 | public function save() |
||
116 | |||
117 | /** |
||
118 | * This method find a record by id |
||
119 | * @params int id |
||
120 | * @return Object |
||
121 | * @throws NoArgumentPassedToFunctionException |
||
122 | */ |
||
123 | public static function find($id) |
||
141 | |||
142 | /** |
||
143 | * This method delete a row from the table by the row id |
||
144 | * @params int id |
||
145 | * @return boolean true or false |
||
146 | * @throws NoRecordDeletionException; |
||
147 | */ |
||
148 | public static function destroy($id) |
||
167 | |||
168 | /** |
||
169 | * This method return the current class name |
||
170 | * $params void |
||
171 | * @return classname |
||
172 | */ |
||
173 | public static function getClassName() |
||
182 | |||
183 | /** |
||
184 | * This method check if the argument passed to this function is an array |
||
185 | * @param $arrayOfRecord |
||
186 | * @return bool |
||
187 | */ |
||
188 | public function checkIfRecordIsEmpty($arrayOfRecord) |
||
197 | |||
198 | } |
||
199 |