Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
FileImportSourceStore | |
0.00% |
0 / 14 |
|
0.00% |
0 / 6 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
load | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
save | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
rollback | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setAssociation | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getImportedId | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace Flow\Import\SourceStore; |
4 | |
5 | use Flow\Import\IImportObject; |
6 | use Flow\Model\UUID; |
7 | |
8 | class FileImportSourceStore implements SourceStoreInterface { |
9 | /** @var string */ |
10 | protected $filename; |
11 | /** @var array */ |
12 | protected $data; |
13 | |
14 | public function __construct( $filename ) { |
15 | $this->filename = $filename; |
16 | $this->load(); |
17 | } |
18 | |
19 | protected function load() { |
20 | if ( file_exists( $this->filename ) ) { |
21 | $this->data = json_decode( file_get_contents( $this->filename ), true ); |
22 | } else { |
23 | $this->data = []; |
24 | } |
25 | } |
26 | |
27 | public function save() { |
28 | $bytesWritten = file_put_contents( $this->filename, json_encode( $this->data ) ); |
29 | if ( $bytesWritten === false ) { |
30 | throw new Exception( 'Could not write out source store to ' . $this->filename ); |
31 | } |
32 | } |
33 | |
34 | public function rollback() { |
35 | $this->load(); |
36 | } |
37 | |
38 | public function setAssociation( UUID $objectId, $importSourceKey ) { |
39 | $this->data[$importSourceKey] = $objectId->getAlphadecimal(); |
40 | } |
41 | |
42 | public function getImportedId( IImportObject $importObject ) { |
43 | $importSourceKey = $importObject->getObjectKey(); |
44 | return isset( $this->data[$importSourceKey] ) |
45 | ? UUID::create( $this->data[$importSourceKey] ) |
46 | : false; |
47 | } |
48 | } |