1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GraphQLAPI\GraphQLAPI\ModuleResolvers; |
6
|
|
|
|
7
|
|
|
use GraphQLAPI\GraphQLAPI\Plugin; |
8
|
|
|
use GraphQLAPI\GraphQLAPI\Facades\ModuleRegistryFacade; |
9
|
|
|
use GraphQLAPI\GraphQLAPI\ModuleResolvers\ModuleResolverTrait; |
10
|
|
|
use GraphQLAPI\GraphQLAPI\ModuleResolvers\SchemaConfigurationFunctionalityModuleResolver; |
11
|
|
|
use GraphQLAPI\GraphQLAPI\ModuleTypeResolvers\ModuleTypeResolver; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* The cache modules have different behavior depending on the environment: |
15
|
|
|
* - "development": visible, disabled by default |
16
|
|
|
* - "production": hidden, enabled by default |
17
|
|
|
* |
18
|
|
|
* @author Leonardo Losoviz <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class CacheFunctionalityModuleResolver extends AbstractCacheFunctionalityModuleResolver |
21
|
|
|
{ |
22
|
|
|
use ModuleResolverTrait; |
23
|
|
|
|
24
|
|
|
public const CONFIGURATION_CACHE = Plugin::NAMESPACE . '\configuration-cache'; |
25
|
|
|
public const SCHEMA_CACHE = Plugin::NAMESPACE . '\schema-cache'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return string[] |
29
|
|
|
*/ |
30
|
|
|
public static function getModulesToResolve(): array |
31
|
|
|
{ |
32
|
|
|
return [ |
33
|
|
|
self::CONFIGURATION_CACHE, |
34
|
|
|
self::SCHEMA_CACHE, |
35
|
|
|
]; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Enable to customize a specific UI for the module |
40
|
|
|
*/ |
41
|
|
|
public function getModuleType(string $module): string |
42
|
|
|
{ |
43
|
|
|
return ModuleTypeResolver::PERFORMANCE; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return array<array> List of entries that must be satisfied, each entry is an array where at least 1 module must be satisfied |
48
|
|
|
*/ |
49
|
|
|
public function getDependedModuleLists(string $module): array |
50
|
|
|
{ |
51
|
|
|
switch ($module) { |
52
|
|
|
case self::CONFIGURATION_CACHE: |
53
|
|
|
return []; |
54
|
|
|
case self::SCHEMA_CACHE: |
55
|
|
|
$moduleRegistry = ModuleRegistryFacade::getInstance(); |
56
|
|
|
return [ |
57
|
|
|
[ |
58
|
|
|
self::CONFIGURATION_CACHE, |
59
|
|
|
], |
60
|
|
|
[ |
61
|
|
|
$moduleRegistry->getInverseDependency(SchemaConfigurationFunctionalityModuleResolver::PUBLIC_PRIVATE_SCHEMA), |
62
|
|
|
], |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
return parent::getDependedModuleLists($module); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getName(string $module): string |
69
|
|
|
{ |
70
|
|
|
$names = [ |
71
|
|
|
self::CONFIGURATION_CACHE => \__('Configuration Cache', 'graphql-api'), |
72
|
|
|
self::SCHEMA_CACHE => \__('Schema Cache', 'graphql-api'), |
73
|
|
|
]; |
74
|
|
|
return $names[$module] ?? $module; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getDescription(string $module): string |
78
|
|
|
{ |
79
|
|
|
switch ($module) { |
80
|
|
|
case self::CONFIGURATION_CACHE: |
81
|
|
|
return \__('Cache the generated application configuration to disk', 'graphql-api'); |
82
|
|
|
case self::SCHEMA_CACHE: |
83
|
|
|
return \__('Cache the generated schema to disk', 'graphql-api'); |
84
|
|
|
} |
85
|
|
|
return parent::getDescription($module); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|