|
1
|
|
|
<?php namespace Algorit\Synchronizer\Request; |
|
2
|
|
|
|
|
3
|
|
|
use Exception; |
|
4
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
5
|
|
|
use Algorit\Synchronizer\Request\Contracts\SystemInterface; |
|
6
|
|
|
|
|
7
|
|
|
class Config { |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* The config array. |
|
11
|
|
|
* |
|
12
|
|
|
* @var array |
|
13
|
|
|
*/ |
|
14
|
|
|
public $config; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The aliases array. |
|
18
|
|
|
* |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
public $aliases; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The date config. |
|
25
|
|
|
* |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
public $date; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The resource instance name. |
|
32
|
|
|
* |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
public $resourceInstance; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The entities config. |
|
39
|
|
|
* |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $entities; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The filesystem instance. |
|
46
|
|
|
* |
|
47
|
|
|
* @var \Illuminate\Filesystem\Filesystem |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $files; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Create a new instance. |
|
53
|
|
|
* |
|
54
|
|
|
* @param \Illuminate\Filesystem\Filesystem $files |
|
55
|
|
|
* @return void |
|
|
|
|
|
|
56
|
|
|
*/ |
|
57
|
|
|
public function __construct(Filesystem $files) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->files = $files; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
protected function load($path) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->config = $this->files->getRequire($path . '/config.php'); |
|
|
|
|
|
|
65
|
|
|
$this->aliases = $this->files->getRequire($path . '/aliases.php'); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Setup the configuration. |
|
72
|
|
|
* |
|
73
|
|
|
* @param \Algorit\Synchronizer\Request\Contracts\SystemInterface $system |
|
74
|
|
|
* @return \Algorit\Synchronizer\Request\Config |
|
75
|
|
|
*/ |
|
76
|
|
|
public function setup(SystemInterface $system, $resource) |
|
77
|
|
|
{ |
|
78
|
|
|
$path = $system->path . '/Config'; |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
if(isset($resource->slug)) |
|
81
|
|
|
{ |
|
82
|
|
|
$path = $system->path . '/Config/' . $resource->slug; |
|
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$this->load($path); |
|
86
|
|
|
|
|
87
|
|
|
if( ! is_array($this->config)) |
|
88
|
|
|
{ |
|
89
|
|
|
throw new Exception('Config files not found.'); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$this->date = array_get($this->config, 'date'); |
|
|
|
|
|
|
93
|
|
|
$this->entities = array_get($this->config, 'entities'); |
|
|
|
|
|
|
94
|
|
|
$this->resourceInstance = array_get($this->config, 'resourceInstance'); |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
if($this->aliases == null or $this->entities == null or $this->date == null) |
|
97
|
|
|
{ |
|
98
|
|
|
throw new Exception('Wrong file format.'); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return $this; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function getConfig() |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->config; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function getAlias($name) |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->aliases[$name]; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Get the entities. |
|
116
|
|
|
* |
|
117
|
|
|
* @param void |
|
118
|
|
|
* @return array |
|
119
|
|
|
*/ |
|
120
|
|
|
public function getEntities() |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->entities; |
|
123
|
|
|
} |
|
124
|
|
|
} |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.