1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apie\ApplicationInfoPlugin\ResourceFactories; |
4
|
|
|
|
5
|
|
|
use Apie\ApplicationInfoPlugin\DataLayers\ApplicationInfoRetriever; |
6
|
|
|
use Apie\ApplicationInfoPlugin\Guesser\AppGuesser; |
7
|
|
|
use Apie\Core\Exceptions\BadConfigurationException; |
8
|
|
|
use Apie\Core\Interfaces\ApiResourceFactoryInterface; |
9
|
|
|
use Apie\Core\Interfaces\ApiResourcePersisterInterface; |
10
|
|
|
use Apie\Core\Interfaces\ApiResourceRetrieverInterface; |
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
|
|
|
*/ |
60
|
|
|
public function getApiResourceRetrieverInstance(string $identifier): ApiResourceRetrieverInterface |
61
|
|
|
{ |
62
|
|
|
$appName = $this->appName ?? AppGuesser::determineApp(); |
63
|
|
|
$environment = $this->environment ?? AppGuesser::determineEnvironment($this->debug); |
|
|
|
|
64
|
|
|
$hash = $this->hash ?? AppGuesser::determineHash(); |
65
|
|
|
return new ApplicationInfoRetriever($appName, $environment, $hash, $this->debug); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Returns true if this factory can create this identifier. |
70
|
|
|
* |
71
|
|
|
* @param string $identifier |
72
|
|
|
* @return bool |
73
|
|
|
*/ |
74
|
|
|
public function hasApiResourcePersisterInstance(string $identifier): bool |
75
|
|
|
{ |
76
|
|
|
return false; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Gets an instance of ApiResourceRetrieverInstance |
81
|
|
|
* @param string $identifier |
82
|
|
|
* @return ApiResourcePersisterInterface |
83
|
|
|
*/ |
84
|
|
|
public function getApiResourcePersisterInstance(string $identifier): ApiResourcePersisterInterface |
85
|
|
|
{ |
86
|
|
|
throw new BadConfigurationException('This method is not supposed to be called'); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|