Newer
Older
use Higidi\Lock\Builder\LockBuilder;
use Higidi\Lock\Configuration\Configuration;
use TYPO3\CMS\Core\Locking\Exception\LockCreateException;
use TYPO3\CMS\Core\Locking\LockFactory as CoreLockFactory;
use TYPO3\CMS\Core\Locking\LockingStrategyInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Factory class creates locks.
*/
class LockFactory extends CoreLockFactory
{
/**
* @var Configuration
*/
protected $configuration;
/**
* @param Configuration|null $configuration The configuration to use
*/
public function __construct(Configuration $configuration = null, LockBuilder $lockBuilder = null)
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{
if (null === $configuration) {
$configuration = GeneralUtility::makeInstance(Configuration::class);
}
$this->configuration = $configuration;
}
/**
* Get the configuration.
*
* @return Configuration
*/
public function getConfiguration()
{
return $this->configuration;
}
/**
* Get best matching locking method
*
* @param string $id ID to identify this lock in the system
* @param int $capabilities LockingStrategyInterface::LOCK_CAPABILITY_* elements combined with bit-wise OR
*
* @return LockingStrategyInterface Class name for a locking method
* @throws LockCreateException if no locker could be created with the requested capabilities
*/
public function createLocker($id, $capabilities = LockingStrategyInterface::LOCK_CAPABILITY_EXCLUSIVE)
{
if (! $this->configuration->isActive()) {
return parent::createLocker($id, $capabilities);
}
$className = $this->configuration->getStrategy();
$locker = GeneralUtility::makeInstance($className, $id);
return $locker;
}
}