X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fsymfony%2Fconsole%2FCommand%2FLockableTrait.php;fp=vendor%2Fsymfony%2Fconsole%2FCommand%2FLockableTrait.php;h=308ebf28c045a447c75b96e0dbab022278b374b6;hp=95597705941cad077118e65faaf71d483f58106f;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/symfony/console/Command/LockableTrait.php b/vendor/symfony/console/Command/LockableTrait.php index 955977059..308ebf28c 100644 --- a/vendor/symfony/console/Command/LockableTrait.php +++ b/vendor/symfony/console/Command/LockableTrait.php @@ -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; } } }