1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yarak\Config; |
4
|
|
|
|
5
|
|
|
use Yarak\Helpers\Str; |
6
|
|
|
|
7
|
|
|
trait PathHelpers |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Get a value from the config array. |
11
|
|
|
* |
12
|
|
|
* @param string|array $value |
13
|
|
|
* |
14
|
|
|
* @return mixed |
15
|
|
|
*/ |
16
|
|
|
abstract public function get($value); |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Return true if config array has given value. |
20
|
|
|
* |
21
|
|
|
* @param mixed $value |
22
|
|
|
* |
23
|
|
|
* @return bool |
24
|
|
|
*/ |
25
|
|
|
abstract public function has($value); |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Validate that a setting exists. |
29
|
|
|
* |
30
|
|
|
* @param array $settings |
31
|
|
|
* |
32
|
|
|
* @throws InvalidConfig |
33
|
|
|
*/ |
34
|
|
|
abstract public function validate(array $settings); |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Return the app path. |
38
|
|
|
* |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
|
|
public function getAppPath() |
42
|
|
|
{ |
43
|
|
|
$this->validate(['application', 'appDir']); |
44
|
|
|
|
45
|
|
|
return Str::append($this->get('application')->get('appDir'), '/'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Return the database directory path. |
50
|
|
|
* |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function getDatabaseDirectory() |
54
|
|
|
{ |
55
|
|
|
$this->validate(['application', 'databaseDir']); |
56
|
|
|
|
57
|
|
|
return Str::append($this->get('application')->get('databaseDir'), '/'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Return the migration directory path. |
62
|
|
|
* |
63
|
|
|
* @param string $path |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
public function getMigrationDirectory($path = '') |
68
|
|
|
{ |
69
|
|
|
return $this->getDatabaseDirectory().'migrations/'.$path; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Return the factory directory path. |
74
|
|
|
* |
75
|
|
|
* @param string $path |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
public function getFactoryDirectory($path = '') |
80
|
|
|
{ |
81
|
|
|
return $this->getDatabaseDirectory().'factories/'.$path; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Return the seeds directory path. |
86
|
|
|
* |
87
|
|
|
* @param string $path |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function getSeedDirectory($path = '') |
92
|
|
|
{ |
93
|
|
|
return $this->getDatabaseDirectory().'seeds/'.$path; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Make database directory structure if it doesn't exist. |
98
|
|
|
*/ |
99
|
|
|
public function getAllDatabaseDirectories() |
100
|
|
|
{ |
101
|
|
|
return [ |
102
|
|
|
'database' => $this->getDatabaseDirectory(), |
103
|
|
|
'migrations' => $this->getMigrationDirectory(), |
104
|
|
|
'factories' => $this->getFactoryDirectory(), |
105
|
|
|
'seeds' => $this->getSeedDirectory(), |
106
|
|
|
]; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Get the console directory path. |
111
|
|
|
* |
112
|
|
|
* @param string $path |
113
|
|
|
* |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
public function getConsoleDirectory($path = '') |
117
|
|
|
{ |
118
|
|
|
$this->validate(['application', 'consoleDir']); |
119
|
|
|
|
120
|
|
|
return Str::append( |
121
|
|
|
$this->get('application')->get('consoleDir'), |
122
|
|
|
'/' |
123
|
|
|
).$path; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Get the commands directory path. |
128
|
|
|
* |
129
|
|
|
* @param string $path |
130
|
|
|
* |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
public function getCommandsDirectory($path = '') |
134
|
|
|
{ |
135
|
|
|
if ($this->has(['application', 'commandsDir'])) { |
136
|
|
|
return Str::append( |
137
|
|
|
$this->get('application')->get('commandsDir'), |
138
|
|
|
'/' |
139
|
|
|
).$path; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
return $this->getConsoleDirectory().'commands/'.$path; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|