File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626 * @param string $table
2727 * @return object
2828 */
29- function use_table ($ table = '' , $ model_type = 'EasyModel ' )
30- {
31- if ($ model_type === 'EasyModel ' ) {
32- $ model = new \Base \Models \EasyModel ;
33- }
34-
35- if ($ model_type === 'BaseModel ' ) {
36- $ model = new \Base \Models \BaseModel ();
37- }
38-
39- if ($ model_type === 'OrmModel ' ) {
40- $ model = new \Base \Models \OrmModel ;
41- }
42-
43- if ($ model_type === 'Model ' ) {
44- $ model = new \Base \Models \Model ;
45- }
46-
29+ function use_table ($ table = '' , $ with = 'EasyModel ' )
30+ {
4731 // This will default to EasyModel unless
48- // $model_type is changed appropriately
49- if (empty ($ table )) {
50- return $ model ;
51- }
52-
53- $ model ->{'table ' } = $ table ; // bypass dynamic property error
32+ // Model type $with is changed appropriately
33+ $ model = match ($ with ) {
34+ 'EasyModel ' => new \Base \Models \EasyModel ,
35+ 'BaseModel ' => new \Base \Models \BaseModel ,
36+ 'OrmModel ' => new \Base \Models \OrmModel ,
37+ 'Model ' => new \Base \Models \Model ,
38+ default => new \Base \Models \EasyModel , // Default to EasyModel
39+ };
40+
41+ if (!empty ($ table )) {
42+ $ model ->{'table ' } = $ table ; // bypass dynamic property error
43+ }
5444
55- return $ model ;
56- }
45+ return $ model ;
46+ }
5747}
5848
5949if ( ! function_exists ( 'use_db ' ))
You can’t perform that action at this time.
0 commit comments