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