1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Support\Nginx; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Finder\Finder; |
6
|
|
|
use Symfony\Component\Finder\SplFileInfo; |
7
|
|
|
|
8
|
|
|
class AvailableConfigurations |
9
|
|
|
{ |
10
|
|
|
protected $locations; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* AvailableConfigurations constructor. |
14
|
|
|
* |
15
|
|
|
* @param array|null $locations |
16
|
|
|
*/ |
17
|
3 |
|
public function __construct($locations = null) |
18
|
|
|
{ |
19
|
3 |
|
$this->locations = $locations ?: $this->locationsFromViewFinder(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Get the list of conf files, indicating current. |
24
|
|
|
* |
25
|
|
|
* @param string|null $highlight |
26
|
|
|
* |
27
|
|
|
* @return mixed |
28
|
|
|
*/ |
29
|
2 |
|
public function getList($highlight = null) |
30
|
|
|
{ |
31
|
2 |
|
return $this->getFileNames() |
32
|
2 |
|
->mapWithKeys(function ($name) use ($highlight) { |
33
|
2 |
|
return [$name => $name.($name == $highlight ? ' (current)' : '')]; |
34
|
2 |
|
})->toArray(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Return the locations being used. |
39
|
|
|
* |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
1 |
|
public function getLocations() |
43
|
|
|
{ |
44
|
1 |
|
return $this->locations; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Retrieve the locations of NGiNX configurations. |
49
|
|
|
* |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
1 |
|
protected function locationsFromViewFinder() |
53
|
|
|
{ |
54
|
1 |
|
return collect(view()->getFinder()->getPaths()) |
55
|
1 |
|
->map(function ($location) { |
56
|
1 |
|
return $location.'/nginx'; |
57
|
1 |
|
})->toArray(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Scour the locations and get a Collection of NGiNX files. |
62
|
|
|
* |
63
|
|
|
* @return \Illuminate\Support\Collection |
64
|
|
|
*/ |
65
|
2 |
|
protected function getFileNames() |
66
|
|
|
{ |
67
|
2 |
|
return collect(iterator_to_array( |
68
|
2 |
|
Finder::create()->in($this->locations)->directories() |
69
|
2 |
|
))->map(function (SplFileInfo $file) { |
70
|
2 |
|
return $file->getFilename(); |
71
|
2 |
|
})->sort(); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|