|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Vox\Webservice; |
|
4
|
|
|
|
|
5
|
|
|
use Metadata\MetadataFactoryInterface; |
|
6
|
|
|
use SplObjectStorage; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* |
|
10
|
|
|
* @author Jhonatan Teixeira <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class Transaction implements TransactionInterface |
|
13
|
|
|
{ |
|
14
|
|
|
use MetadataTrait; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var SplObjectStorage |
|
18
|
|
|
*/ |
|
19
|
|
|
private $storage; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var TransferManagerInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
private $transferManager; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var WebserviceClientInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
private $webServiceClient; |
|
30
|
|
|
|
|
31
|
|
|
private $states = [ |
|
32
|
|
|
'created' => 'delete', |
|
33
|
|
|
'updated' => 'put', |
|
34
|
|
|
'deleted' => 'post', |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
1 |
|
public function __construct( |
|
38
|
|
|
TransferManagerInterface $transferManager, |
|
39
|
|
|
WebserviceClientInterface $webServiceClient, |
|
40
|
|
|
MetadataFactoryInterface $metadataFactory |
|
41
|
|
|
) { |
|
42
|
1 |
|
$this->storage = new SplObjectStorage(); |
|
43
|
1 |
|
$this->transferManager = $transferManager; |
|
44
|
1 |
|
$this->webServiceClient = $webServiceClient; |
|
45
|
1 |
|
$this->metadataFactory = $metadataFactory; |
|
46
|
1 |
|
} |
|
47
|
|
|
|
|
48
|
1 |
|
public function addCreated($object) |
|
49
|
|
|
{ |
|
50
|
1 |
|
$this->storage[$object] = $this->states['created']; |
|
51
|
1 |
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
public function addUpdated($object) |
|
54
|
|
|
{ |
|
55
|
1 |
|
$this->storage[$object] = $this->states['updated']; |
|
56
|
1 |
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
public function addDeleted($object) |
|
59
|
|
|
{ |
|
60
|
1 |
|
$this->storage[$object] = $this->states['deleted']; |
|
61
|
1 |
|
} |
|
62
|
|
|
|
|
63
|
1 |
|
public function rollback() |
|
64
|
|
|
{ |
|
65
|
1 |
|
foreach ($this->storage as $object) { |
|
66
|
1 |
|
$state = $this->storage->getInfo(); |
|
67
|
1 |
|
$args = [$object]; |
|
68
|
|
|
|
|
69
|
1 |
|
if ($state == 'delete') { |
|
70
|
1 |
|
$args= [get_class($object), $this->getIdValue($object)]; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
1 |
|
call_user_func([$this->webServiceClient, $state], ...$args); |
|
74
|
|
|
} |
|
75
|
1 |
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|