1 | <?php |
||
15 | class ConfigFactory implements ConfigContract, Arrayable, Jsonable, JsonSerializable |
||
16 | { |
||
17 | use HasAttributesTrait; |
||
18 | |||
19 | protected $app; |
||
20 | protected $name; |
||
21 | protected $configRepository; |
||
22 | |||
23 | protected $title; |
||
24 | protected $permissions; |
||
25 | protected $columns; |
||
26 | protected $model; |
||
27 | protected $elements; |
||
28 | |||
29 | public function __construct(Application $app, $name) |
||
30 | { |
||
31 | $this->app = $app; |
||
32 | $this->name = $name; |
||
33 | |||
34 | $this->configRepository = new ConfigRepository( |
||
35 | $this->app['files']->getRequire($this->getConfigFile()) |
||
36 | ); |
||
37 | } |
||
38 | |||
39 | private function getConfigFile() |
||
40 | { |
||
41 | return $this->app['path.config'] |
||
42 | . DIRECTORY_SEPARATOR . 'admin' |
||
43 | . DIRECTORY_SEPARATOR . $this->name . '.php'; |
||
44 | } |
||
45 | |||
46 | public function getConfigRepository() |
||
47 | { |
||
48 | return $this->configRepository; |
||
49 | } |
||
50 | |||
51 | |||
52 | public function getTitle() |
||
53 | { |
||
54 | if (!$this->title) { |
||
55 | $this->title = $this->configRepository->get('title'); |
||
56 | } |
||
57 | |||
58 | return $this->title; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @return \Sco\Admin\Config\PermissionsConfig |
||
63 | */ |
||
64 | public function getPermissions() |
||
65 | { |
||
66 | if (!$this->permissions) { |
||
67 | $config = $this->configRepository->get('permissions'); |
||
68 | |||
69 | $this->permissions = new PermissionsConfig($config); |
||
70 | } |
||
71 | |||
72 | return $this->permissions; |
||
73 | } |
||
74 | |||
75 | public function getColumns() |
||
76 | { |
||
77 | if (!$this->columns) { |
||
78 | $config = $this->configRepository->get('columns'); |
||
79 | |||
80 | $this->columns = collect($config)->mapWithKeys(function ($item, $key) { |
||
81 | $columnClass = config('admin.column'); |
||
82 | return [$key => new $columnClass($key, $item)]; |
||
83 | }); |
||
84 | } |
||
85 | |||
86 | return $this->columns; |
||
87 | } |
||
88 | |||
89 | protected function getElements() |
||
90 | { |
||
91 | if (!$this->elements) { |
||
92 | $config = $this->configRepository->get('elements'); |
||
93 | $this->elements = collect($config)->mapWithKeys(function ($item, $key) { |
||
94 | $type = isset($item['type']) ? $item['type'] : 'text'; |
||
95 | return [$key => AdminElement::{$type}($key, $item['title'])]; |
||
96 | }); |
||
97 | } |
||
98 | |||
99 | return $this->elements; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @return \Sco\Admin\Config\ModelConfig |
||
104 | */ |
||
105 | public function getModel() |
||
112 | |||
113 | public function getRules() |
||
114 | { |
||
115 | return $this->configRepository->get('rules'); |
||
116 | } |
||
117 | |||
118 | public function getConfigs() |
||
119 | { |
||
120 | return [ |
||
128 | |||
129 | public function __toString() |
||
133 | } |
||
134 |