1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Startwind\Inventorio\Collector\Frameworks\Php; |
4
|
|
|
|
5
|
|
|
use Startwind\Inventorio\Collector\Application\WebServer\Apache\ApacheServerNameCollector; |
6
|
|
|
use Startwind\Inventorio\Collector\BasicCollector; |
7
|
|
|
use Startwind\Inventorio\Collector\InventoryAwareCollector; |
8
|
|
|
use Startwind\Inventorio\Exec\File; |
9
|
|
|
|
10
|
|
|
class SymfonyCollector extends BasicCollector implements InventoryAwareCollector |
11
|
|
|
{ |
12
|
|
|
protected string $identifier = 'FrameworkPHPSymfony'; |
13
|
|
|
private array $inventory; |
14
|
|
|
|
15
|
|
|
public function setInventory(array $inventory): void |
16
|
|
|
{ |
17
|
|
|
$this->inventory = $inventory; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function collect(): array |
21
|
|
|
{ |
22
|
|
|
if (!array_key_exists(ApacheServerNameCollector::COLLECTION_IDENTIFIER, $this->inventory) |
23
|
|
|
|| !is_array($this->inventory[ApacheServerNameCollector::COLLECTION_IDENTIFIER]) |
24
|
|
|
) return []; |
25
|
|
|
|
26
|
|
|
$configs = $this->inventory[ApacheServerNameCollector::COLLECTION_IDENTIFIER]; |
27
|
|
|
|
28
|
|
|
$file = File::getInstance(); |
29
|
|
|
|
30
|
|
|
$symfonyDomains = []; |
31
|
|
|
|
32
|
|
|
foreach ($configs as $config) { |
33
|
|
|
$domain = $config[ApacheServerNameCollector::FIELD_SERVER_NAME]; |
34
|
|
|
$documentRoot = $config[ApacheServerNameCollector::FIELD_DOCUMENT_ROOT]; |
35
|
|
|
|
36
|
|
|
if ($file->fileExists($documentRoot . '/../composer.lock')) { |
37
|
|
|
$composerLockRaw = File::getInstance()->getContents($documentRoot . '/../composer.lock'); |
38
|
|
|
$composerLock = json_decode($composerLockRaw, true); |
39
|
|
|
|
40
|
|
|
if (array_key_exists('packages', $composerLock) && is_array($composerLock['packages'])) { |
41
|
|
|
foreach ($composerLock['packages'] as $package) { |
42
|
|
|
if ($package['name'] === 'ssymfony/framework-bundle') { |
43
|
|
|
$symfonyDomains[$domain] = [ |
44
|
|
|
'version' => $package['version'], |
45
|
|
|
'path' => $file->realPath($documentRoot . '/../') |
46
|
|
|
]; |
47
|
|
|
break; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return [ |
55
|
|
|
'framework' => $symfonyDomains |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|