| 1 | <?php |
||
| 8 | class AbstractionLayer implements AbstractionLayerContract |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var EloquentModel |
||
| 12 | */ |
||
| 13 | protected $model; |
||
| 14 | |||
| 15 | /** |
||
| 16 | */ |
||
| 17 | 9 | public function __construct(EloquentModel $model) |
|
| 21 | |||
| 22 | 1 | public function getModel() |
|
| 23 | { |
||
| 24 | 1 | return $this->model; |
|
| 25 | } |
||
| 26 | |||
| 27 | 4 | protected function getSchemaManager() |
|
| 28 | { |
||
| 29 | 4 | $connection = Schema::getConnection(); |
|
| 30 | |||
| 31 | 4 | return $connection->getDoctrineSchemaManager(); |
|
| 32 | } |
||
| 33 | |||
| 34 | 4 | public function getTableColumns() |
|
| 35 | { |
||
| 36 | 4 | $sm = $this->getSchemaManager(); |
|
| 37 | |||
| 38 | 4 | $columns = $sm->listTableColumns($this->model->getTable()); |
|
| 39 | |||
| 40 | 4 | return $columns; |
|
| 41 | } |
||
| 42 | |||
| 43 | 2 | public function getTableColumn($name) |
|
| 44 | { |
||
| 45 | 2 | $columns = $this->getTableColumns(); |
|
| 46 | |||
| 47 | 2 | if (! array_key_exists($name, $columns)) { |
|
| 48 | 1 | throw new \Exception("Column ".$name." not found on ".$this->model->getTable()); |
|
| 49 | } |
||
| 50 | |||
| 51 | 1 | return $columns[$name]; |
|
| 52 | } |
||
| 53 | |||
| 54 | 1 | public function getModelAttributes() |
|
| 55 | { |
||
| 56 | 1 | $columns = $this->getTableColumns(); |
|
| 57 | |||
| 58 | 1 | $attributes = []; |
|
| 59 | 1 | foreach ($columns as $fieldName => $field) { |
|
| 60 | 1 | $attributes[] = $fieldName; |
|
| 61 | 1 | } |
|
| 62 | |||
| 63 | 1 | return $attributes; |
|
| 64 | } |
||
| 65 | |||
| 66 | public function getTableForeignKeys() |
||
| 74 | } |
||
| 75 |