‪TYPO3CMS  10.4
LockFactory.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
25 {
29  protected ‪$lockingStrategy = [
30  SemaphoreLockStrategy::class => true,
31  FileLockStrategy::class => true,
32  SimpleLockStrategy::class => true
33  ];
34 
41  public function ‪addLockingStrategy($className)
42  {
43  $interfaces = class_implements($className);
44  if (isset($interfaces[LockingStrategyInterface::class])) {
45  $this->lockingStrategy[$className] = true;
46  } else {
47  throw new \InvalidArgumentException('The given class name ' . $className . ' does not implement the required LockingStrategyInterface interface.', 1425990198);
48  }
49  }
50 
56  public function ‪removeLockingStrategy($className)
57  {
58  unset($this->lockingStrategy[$className]);
59  }
60 
70  {
71  $queue = new \SplPriorityQueue();
72 
74  foreach ($this->lockingStrategy as $method => $_) {
75  $supportedCapabilities = $capabilities & $method::getCapabilities();
76  if ($supportedCapabilities === $capabilities) {
77  $queue->insert($method, $method::getPriority());
78  }
79  }
80  if ($queue->count() > 0) {
81  $className = $queue->top();
82  // We use 'new' here on purpose!
83  // Locking might be used very early in the bootstrap process, where makeInstance() does not work
84  return new $className($id);
85  }
86  throw new ‪LockCreateException('Could not find a matching locking method with requested capabilities.', 1425990190);
87  }
88 }
‪TYPO3\CMS\Core\Locking\LockFactory\addLockingStrategy
‪addLockingStrategy($className)
Definition: LockFactory.php:40
‪TYPO3\CMS\Core\Locking
‪TYPO3\CMS\Core\Locking\LockingStrategyInterface
Definition: LockingStrategyInterface.php:26
‪TYPO3\CMS\Core\Locking\LockingStrategyInterface\LOCK_CAPABILITY_EXCLUSIVE
‪const LOCK_CAPABILITY_EXCLUSIVE
Definition: LockingStrategyInterface.php:30
‪TYPO3\CMS\Core\Locking\LockFactory\createLocker
‪LockingStrategyInterface createLocker($id, $capabilities=LockingStrategyInterface::LOCK_CAPABILITY_EXCLUSIVE)
Definition: LockFactory.php:68
‪TYPO3\CMS\Core\Locking\LockFactory\removeLockingStrategy
‪removeLockingStrategy($className)
Definition: LockFactory.php:55
‪TYPO3\CMS\Core\Locking\LockFactory\$lockingStrategy
‪bool[] $lockingStrategy
Definition: LockFactory.php:28
‪TYPO3\CMS\Core\Locking\Exception\LockCreateException
Definition: LockCreateException.php:24
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪TYPO3\CMS\Core\Locking\LockFactory
Definition: LockFactory.php:25