Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

LockableTrait.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 1.72 KiB


01  <?php
02   
03  /*
04   * This file is part of the Symfony package.
05   *
06   * (c) Fabien Potencier <fabien@symfony.com>
07   *
08   * For the full copyright and license information, please view the LICENSE
09   * 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\Console\Exception\RuntimeException;
16  use Symfony\Component\Lock\Factory;
17  use Symfony\Component\Lock\Lock;
18  use Symfony\Component\Lock\Store\FlockStore;
19  use Symfony\Component\Lock\Store\SemaphoreStore;
20   
21  /**
22   * Basic lock feature for commands.
23   *
24   * @author Geoffrey Brier <geoffrey.brier@gmail.com>
25   */
26  trait LockableTrait
27  {
28      /** @var Lock */
29      private $lock;
30   
31      /**
32       * Locks a command.
33       *
34       * @return bool
35       */
36      private function lock($name = null, $blocking = false)
37      {
38          if (!class_exists(SemaphoreStore::class)) {
39              throw new RuntimeException('To enable the locking feature you must install the symfony/lock component.');
40          }
41   
42          if (null !== $this->lock) {
43              throw new LogicException('A lock is already in place.');
44          }
45   
46          if (SemaphoreStore::isSupported($blocking)) {
47              $store = new SemaphoreStore();
48          } else {
49              $store = new FlockStore();
50          }
51   
52          $this->lock = (new Factory($store))->createLock($name ?: $this->getName());
53          if (!$this->lock->acquire($blocking)) {
54              $this->lock = null;
55   
56              return false;
57          }
58   
59          return true;
60      }
61   
62      /**
63       * Releases the command lock if there is one.
64       */
65      private function release()
66      {
67          if ($this->lock) {
68              $this->lock->release();
69              $this->lock = null;
70          }
71      }
72  }
73