|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Vox\Webservice; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\Collection; |
|
6
|
|
|
use Doctrine\Common\Persistence\ObjectRepository; |
|
7
|
|
|
use Vox\Webservice\Proxy\ProxyFactoryInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* the transfer repository does the job of requiring data from the webservice client for the correct transfer |
|
11
|
|
|
* however this pattern should be more flexible, a future release will fix this |
|
12
|
|
|
* |
|
13
|
|
|
* @author Jhonatan Teixeira <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
final class TransferRepository implements ObjectRepository |
|
16
|
|
|
{ |
|
17
|
|
|
private $transferName; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var WebserviceClientInterface |
|
21
|
|
|
*/ |
|
22
|
|
|
private $webserviceClient; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var ObjectStorageInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
private $objectStorage; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var TransferManagerInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
private $transferManager; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var ProxyFactoryInterface |
|
36
|
|
|
*/ |
|
37
|
|
|
private $proxyFactory; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string $transferName |
|
41
|
|
|
* @param \Vox\Webservice\WebserviceClientInterface $webserviceClient |
|
42
|
|
|
* @param \Vox\Webservice\ObjectStorageInterface $objectStorage |
|
43
|
|
|
* @param \Vox\Webservice\TransferManagerInterface $transferManager |
|
44
|
|
|
* @param ProxyFactoryInterface $proxyFactory |
|
45
|
|
|
*/ |
|
46
|
9 |
|
public function __construct( |
|
47
|
|
|
string $transferName, |
|
48
|
|
|
WebserviceClientInterface $webserviceClient, |
|
49
|
|
|
ObjectStorageInterface $objectStorage, |
|
50
|
|
|
TransferManagerInterface $transferManager, |
|
51
|
|
|
ProxyFactoryInterface $proxyFactory |
|
52
|
|
|
) { |
|
53
|
9 |
|
$this->transferName = $transferName; |
|
54
|
9 |
|
$this->webserviceClient = $webserviceClient; |
|
55
|
9 |
|
$this->objectStorage = $objectStorage; |
|
56
|
9 |
|
$this->transferManager = $transferManager; |
|
57
|
9 |
|
$this->proxyFactory = $proxyFactory; |
|
58
|
9 |
|
} |
|
59
|
|
|
|
|
60
|
5 |
|
public function find($id) |
|
61
|
|
|
{ |
|
62
|
5 |
|
$transfer = $this->objectStorage->fetchByParams($this->transferName, $id) |
|
63
|
5 |
|
?? $this->proxyFactory |
|
64
|
5 |
|
->createProxy($this->webserviceClient->get($this->transferName, $id), $this->transferManager); |
|
65
|
|
|
|
|
66
|
5 |
|
if ($transfer && !$this->objectStorage->contains($transfer)) { |
|
67
|
5 |
|
$this->objectStorage->attach($transfer); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
5 |
|
return $transfer; |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
2 |
|
public function findAll(): Collection |
|
74
|
|
|
{ |
|
75
|
2 |
|
$collection = $this->webserviceClient->cGet($this->transferName); |
|
76
|
|
|
|
|
77
|
2 |
|
$collection->setObjectStorage($this->objectStorage) |
|
78
|
2 |
|
->setTransferManager($this->transferManager) |
|
79
|
2 |
|
->setProxyFactory($this->proxyFactory); |
|
80
|
|
|
|
|
81
|
2 |
|
return $collection; |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
1 |
|
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): Collection |
|
85
|
|
|
{ |
|
86
|
1 |
|
$collection = $this->webserviceClient->cGet($this->transferName, $criteria); |
|
87
|
|
|
|
|
88
|
1 |
|
$collection->setObjectStorage($this->objectStorage) |
|
89
|
1 |
|
->setTransferManager($this->transferManager) |
|
90
|
1 |
|
->setProxyFactory($this->proxyFactory); |
|
91
|
|
|
|
|
92
|
1 |
|
return $collection; |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
1 |
|
public function findOneBy(array $criteria) |
|
96
|
|
|
{ |
|
97
|
1 |
|
$collection = $this->webserviceClient->cGet($this->transferName, $criteria); |
|
98
|
|
|
|
|
99
|
1 |
|
$collection->setObjectStorage($this->objectStorage) |
|
100
|
1 |
|
->setTransferManager($this->transferManager) |
|
101
|
1 |
|
->setProxyFactory($this->proxyFactory); |
|
102
|
|
|
|
|
103
|
1 |
|
if ($collection->count() > 0) { |
|
104
|
1 |
|
return $collection->first(); |
|
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function getClassName(): string |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->transferName; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|