|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace W2w\Lib\Apie\Plugins\ApplicationInfo\ResourceFactories; |
|
4
|
|
|
|
|
5
|
|
|
use W2w\Lib\Apie\Exceptions\BadConfigurationException; |
|
6
|
|
|
use W2w\Lib\Apie\Interfaces\ApiResourceFactoryInterface; |
|
7
|
|
|
use W2w\Lib\Apie\Interfaces\ApiResourcePersisterInterface; |
|
8
|
|
|
use W2w\Lib\Apie\Interfaces\ApiResourceRetrieverInterface; |
|
9
|
|
|
use W2w\Lib\Apie\Plugins\ApplicationInfo\DataLayers\ApplicationInfoRetriever; |
|
10
|
|
|
use W2w\Lib\Apie\Plugins\ApplicationInfo\Guesser\AppGuesser; |
|
11
|
|
|
|
|
12
|
|
|
class ApplicationInfoRetrieverFallbackFactory implements ApiResourceFactoryInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var string|null |
|
16
|
|
|
*/ |
|
17
|
|
|
private $appName; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string|null |
|
21
|
|
|
*/ |
|
22
|
|
|
private $environment; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var string|null |
|
26
|
|
|
*/ |
|
27
|
|
|
private $hash; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var bool|null |
|
31
|
|
|
*/ |
|
32
|
|
|
private $debug; |
|
33
|
|
|
|
|
34
|
|
|
public function __construct( |
|
35
|
|
|
?string $appName = null, |
|
36
|
|
|
?string $environment = null, |
|
37
|
|
|
?string $hash = null, |
|
38
|
|
|
bool $debug = true |
|
39
|
|
|
) { |
|
40
|
|
|
$this->appName = $appName; |
|
41
|
|
|
$this->environment = $environment; |
|
42
|
|
|
$this->hash = $hash; |
|
43
|
|
|
$this->debug = $debug; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Returns true if this factory can create this identifier. |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $identifier |
|
50
|
|
|
* @return bool |
|
51
|
|
|
*/ |
|
52
|
|
|
public function hasApiResourceRetrieverInstance(string $identifier): bool |
|
53
|
|
|
{ |
|
54
|
|
|
return $identifier === ApplicationInfoRetriever::class; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Gets an instance of ApiResourceRetrieverInstance |
|
59
|
|
|
* @param string $identifier |
|
60
|
|
|
* @return ApiResourceRetrieverInterface |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getApiResourceRetrieverInstance(string $identifier): ApiResourceRetrieverInterface |
|
63
|
|
|
{ |
|
64
|
|
|
$appName = $this->appName ?? AppGuesser::determineApp(); |
|
65
|
|
|
$environment = $this->environment ?? AppGuesser::determineEnvironment($this->debug); |
|
|
|
|
|
|
66
|
|
|
$hash = $this->hash ?? AppGuesser::determineHash(); |
|
67
|
|
|
return new ApplicationInfoRetriever($appName, $environment, $hash, $this->debug); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Returns true if this factory can create this identifier. |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $identifier |
|
74
|
|
|
* @return bool |
|
75
|
|
|
*/ |
|
76
|
|
|
public function hasApiResourcePersisterInstance(string $identifier): bool |
|
77
|
|
|
{ |
|
78
|
|
|
return false; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Gets an instance of ApiResourceRetrieverInstance |
|
83
|
|
|
* @param string $identifier |
|
84
|
|
|
* @return ApiResourcePersisterInterface |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getApiResourcePersisterInstance(string $identifier): ApiResourcePersisterInterface |
|
87
|
|
|
{ |
|
88
|
|
|
throw new BadConfigurationException('This call is not supposed to be called'); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|