[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <[email protected]> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\Console\Command; 13 14 use Symfony\Component\Console\Exception\LogicException; 15 use Symfony\Component\Lock\LockFactory; 16 use Symfony\Component\Lock\LockInterface; 17 use Symfony\Component\Lock\Store\FlockStore; 18 use Symfony\Component\Lock\Store\SemaphoreStore; 19 20 /** 21 * Basic lock feature for commands. 22 * 23 * @author Geoffrey Brier <[email protected]> 24 */ 25 trait LockableTrait 26 { 27 /** @var LockInterface|null */ 28 private $lock; 29 30 /** 31 * Locks a command. 32 */ 33 private function lock(string $name = null, bool $blocking = false): bool 34 { 35 if (!class_exists(SemaphoreStore::class)) { 36 throw new LogicException('To enable the locking feature you must install the symfony/lock component.'); 37 } 38 39 if (null !== $this->lock) { 40 throw new LogicException('A lock is already in place.'); 41 } 42 43 if (SemaphoreStore::isSupported()) { 44 $store = new SemaphoreStore(); 45 } else { 46 $store = new FlockStore(); 47 } 48 49 $this->lock = (new LockFactory($store))->createLock($name ?: $this->getName()); 50 if (!$this->lock->acquire($blocking)) { 51 $this->lock = null; 52 53 return false; 54 } 55 56 return true; 57 } 58 59 /** 60 * Releases the command lock if there is one. 61 */ 62 private function release() 63 { 64 if ($this->lock) { 65 $this->lock->release(); 66 $this->lock = null; 67 } 68 } 69 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |