4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Console\Command;
14 use Symfony\Component\Console\Exception\LogicException;
15 use Symfony\Component\Console\Exception\RuntimeException;
16 use Symfony\Component\Filesystem\LockHandler;
19 * Basic lock feature for commands.
21 * @author Geoffrey Brier <geoffrey.brier@gmail.com>
32 private function lock($name = null, $blocking = false)
34 if (!class_exists(LockHandler::class)) {
35 throw new RuntimeException('To enable the locking feature you must install the symfony/filesystem component.');
38 if (null !== $this->lockHandler) {
39 throw new LogicException('A lock is already in place.');
42 $this->lockHandler = new LockHandler($name ?: $this->getName());
44 if (!$this->lockHandler->lock($blocking)) {
45 $this->lockHandler = null;
54 * Releases the command lock if there is one.
56 private function release()
58 if ($this->lockHandler) {
59 $this->lockHandler->release();
60 $this->lockHandler = null;