1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Utils\Generators\ReverseSequenceGenerator |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2021 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Utils\Generators; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\CacheKeys; |
24
|
|
|
use TechDivision\Import\Services\RegistryProcessorInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Generator implementation that generates reeverse sequences starting from -1. |
28
|
|
|
* |
29
|
|
|
* @author Tim Wagner <[email protected]> |
30
|
|
|
* @copyright 2021 TechDivision GmbH <[email protected]> |
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
32
|
|
|
* @link https://github.com/techdivision/import |
33
|
|
|
* @link http://www.techdivision.com |
34
|
|
|
*/ |
35
|
|
|
class ReverseSequenceGenerator implements GeneratorInterface |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The registry processor instance used to generate the inversed entity IDs. |
40
|
|
|
* |
41
|
|
|
* @var \TechDivision\Import\Services\RegistryProcessorInterface |
42
|
|
|
*/ |
43
|
|
|
private $registryProcessor; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Initializes the generator with the registry processor. |
47
|
|
|
* |
48
|
|
|
* @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance |
49
|
|
|
*/ |
50
|
|
|
public function __construct(RegistryProcessorInterface $registryProcessor) |
51
|
|
|
{ |
52
|
|
|
$this->registryProcessor = $registryProcessor; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Creates a new negative sequence for caching purposes. |
57
|
|
|
* |
58
|
|
|
* @param string $counterName The counter name that has to be lowered |
59
|
|
|
* |
60
|
|
|
* @return int The unique sequence |
61
|
|
|
* @see \TechDivision\Import\Utils\Generators\GeneratorInterface::generate() |
62
|
|
|
*/ |
63
|
|
|
public function generate(string $counterName = 'generic') |
64
|
|
|
{ |
65
|
|
|
return $this->registryProcessor->lowerCounter(CacheKeys::SEQUENCES, $counterName); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|