-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathModuleManager.php
More file actions
89 lines (79 loc) · 2.59 KB
/
ModuleManager.php
File metadata and controls
89 lines (79 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* Copyright © Magefan (support@magefan.com). All rights reserved.
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
*/
declare(strict_types=1);
namespace Magefan\Community\Model;
class ModuleManager
{
private $moduleManager = [
'mfseo' => [
'plus' => ['mfrichsnippets','mfxmlsitemap','mfhs'],
'extra' => ['alternatehreflang','mfogt','mftwittercards']
],
'mfspeedoptimizations' => [
'base' => ['mflazyzoad','mfrocketjavascript'],
'plus' => ['mfwebp'],
'extra' => ['mfpagecachewarmer']
],
];
/**
* @var GetModuleVersion
*/
private $getModuleVersion;
/**
* @var SectionFactory
*/
private $sectionFactory;
/**
* @param GetModuleVersion $getModuleVersion
* @param SectionFactory $sectionFactory
*/
public function __construct(
GetModuleVersion $getModuleVersion,
SectionFactory $sectionFactory
)
{
$this->getModuleVersion = $getModuleVersion;
$this->sectionFactory = $sectionFactory;
}
/**
* @return array
*/
public function getAllSections()
{
$allInstModule = [];
foreach ($this->moduleManager as $section => $plans) {
$extensionName = $this->sectionFactory->create(['name' => $section])->getModuleName();
$extensionName = str_replace(['Extra','Plus'],'', $extensionName);
foreach ($plans as $key => $modules) {
if ($key == 'base' ||$this->getModuleVersion->execute('Magefan_' . $extensionName . ucfirst($key))) {
$allInstModule[$section] = array_merge($allInstModule[$section] ?? [], $modules);
}
}
}
return $allInstModule;
}
/**
* @param $name
* @return array|null
*/
public function getSectionByName($name)
{
if (isset($this->moduleManager[$name])) {
$sections = [];
foreach ($this->moduleManager[$name] as $plan => $data) {
foreach ($data as $section) {
$extensionName = $this->sectionFactory->create(['name' => $section])->getModuleName();
$extensionName = str_replace(['Extra','Plus'],'', $extensionName);
if ($plan == 'base' || $this->getModuleVersion->execute('Magefan_' . $extensionName . ucfirst($plan))) {
$sections[] = $section;
}
}
}
return $sections;
}
return null;
}
}