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