PluginProbe
Depicter — Popup & Slider Builder / 1.3.2
Depicter — Popup & Slider Builder v1.3.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / symfony / console / Command / LockableTrait.php

LockableTrait.php in Depicter — Popup & Slider Builder 1.3.2, at vendor/symfony/console/Command/LockableTrait.php

70 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
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\Lock;
16 use Symfony\Component\Lock\LockFactory;
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 <geoffrey.brier@gmail.com>
24 */
25 trait LockableTrait
26 {
27 /** @var Lock */
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 }
70