Total Complexity | 5 |
Total Lines | 25 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | class ModelProxy |
||
8 | { |
||
9 | protected $model; |
||
10 | |||
11 | protected $runningInQuery; |
||
12 | |||
13 | public function __construct($model, $runningInQuery) |
||
14 | { |
||
15 | $this->model = $model; |
||
16 | $this->runningInQuery = $runningInQuery; |
||
17 | } |
||
18 | |||
19 | public function __get($key) |
||
20 | { |
||
21 | return $this->runningInQuery ? $this->getTableField($key) : $this->getModelAttribute($key); |
||
22 | } |
||
23 | |||
24 | protected function getTableField($key) |
||
25 | { |
||
26 | return new Expression($this->model->getTable() . '.' . $key); |
||
27 | } |
||
28 | |||
29 | protected function getModelAttribute($key) |
||
32 | } |
||
33 | } |
||
34 |