1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apie\FileStoragePlugin\ResourceFactories; |
4
|
|
|
|
5
|
|
|
use Apie\Core\IdentifierExtractor; |
6
|
|
|
use Apie\Core\Interfaces\ApiResourceFactoryInterface; |
7
|
|
|
use Apie\Core\Interfaces\ApiResourcePersisterInterface; |
8
|
|
|
use Apie\Core\Interfaces\ApiResourceRetrieverInterface; |
9
|
|
|
use Apie\FileStoragePlugin\DataLayers\FileStorageDataLayer; |
10
|
|
|
|
11
|
|
|
class FileStorageDataLayerFactory implements ApiResourceFactoryInterface |
12
|
|
|
{ |
13
|
|
|
private $path; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var IdentifierExtractor |
17
|
|
|
*/ |
18
|
|
|
private $identifierExtractor; |
19
|
|
|
|
20
|
|
|
public function __construct(string $path, IdentifierExtractor $identifierExtractor) |
21
|
|
|
{ |
22
|
|
|
$this->path = $path; |
23
|
|
|
$this->identifierExtractor = $identifierExtractor; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Returns true if this factory can create this identifier. |
28
|
|
|
* |
29
|
|
|
* @param string $identifier |
30
|
|
|
* @return bool |
31
|
|
|
*/ |
32
|
|
|
public function hasApiResourceRetrieverInstance(string $identifier): bool |
33
|
|
|
{ |
34
|
|
|
return $identifier === FileStorageDataLayer::class; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Gets an instance of ApiResourceRetrieverInstance |
39
|
|
|
* @param string $identifier |
40
|
|
|
* @return ApiResourceRetrieverInterface |
41
|
|
|
*/ |
42
|
|
|
public function getApiResourceRetrieverInstance(string $identifier): ApiResourceRetrieverInterface |
43
|
|
|
{ |
44
|
|
|
return new FileStorageDataLayer($this->path, $this->identifierExtractor); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Returns true if this factory can create this identifier. |
49
|
|
|
* |
50
|
|
|
* @param string $identifier |
51
|
|
|
* @return bool |
52
|
|
|
*/ |
53
|
|
|
public function hasApiResourcePersisterInstance(string $identifier): bool |
54
|
|
|
{ |
55
|
|
|
return $identifier === FileStorageDataLayer::class; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Gets an instance of ApiResourceRetrieverInstance |
60
|
|
|
* @param string $identifier |
61
|
|
|
* @return ApiResourcePersisterInterface |
62
|
|
|
*/ |
63
|
|
|
public function getApiResourcePersisterInstance(string $identifier): ApiResourcePersisterInterface |
64
|
|
|
{ |
65
|
|
|
return new FileStorageDataLayer($this->path, $this->identifierExtractor); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|