Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / console / Command / LockableTrait.php
index 95597705941cad077118e65faaf71d483f58106f..308ebf28c045a447c75b96e0dbab022278b374b6 100644 (file)
@@ -13,7 +13,10 @@ namespace Symfony\Component\Console\Command;
 
 use Symfony\Component\Console\Exception\LogicException;
 use Symfony\Component\Console\Exception\RuntimeException;
-use Symfony\Component\Filesystem\LockHandler;
+use Symfony\Component\Lock\Factory;
+use Symfony\Component\Lock\Lock;
+use Symfony\Component\Lock\Store\FlockStore;
+use Symfony\Component\Lock\Store\SemaphoreStore;
 
 /**
  * Basic lock feature for commands.
@@ -22,7 +25,8 @@ use Symfony\Component\Filesystem\LockHandler;
  */
 trait LockableTrait
 {
-    private $lockHandler;
+    /** @var Lock */
+    private $lock;
 
     /**
      * Locks a command.
@@ -31,18 +35,23 @@ trait LockableTrait
      */
     private function lock($name = null, $blocking = false)
     {
-        if (!class_exists(LockHandler::class)) {
-            throw new RuntimeException('To enable the locking feature you must install the symfony/filesystem component.');
+        if (!class_exists(SemaphoreStore::class)) {
+            throw new RuntimeException('To enable the locking feature you must install the symfony/lock component.');
         }
 
-        if (null !== $this->lockHandler) {
+        if (null !== $this->lock) {
             throw new LogicException('A lock is already in place.');
         }
 
-        $this->lockHandler = new LockHandler($name ?: $this->getName());
+        if (SemaphoreStore::isSupported($blocking)) {
+            $store = new SemaphoreStore();
+        } else {
+            $store = new FlockStore();
+        }
 
-        if (!$this->lockHandler->lock($blocking)) {
-            $this->lockHandler = null;
+        $this->lock = (new Factory($store))->createLock($name ?: $this->getName());
+        if (!$this->lock->acquire($blocking)) {
+            $this->lock = null;
 
             return false;
         }
@@ -55,9 +64,9 @@ trait LockableTrait
      */
     private function release()
     {
-        if ($this->lockHandler) {
-            $this->lockHandler->release();
-            $this->lockHandler = null;
+        if ($this->lock) {
+            $this->lock->release();
+            $this->lock = null;
         }
     }
 }