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

FallbackVersions.php

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


001  <?php
002   
003  declare(strict_types=1);
004   
005  namespace PackageVersions;
006   
007  use Generator;
008  use OutOfBoundsException;
009  use UnexpectedValueException;
010  use function array_key_exists;
011  use function array_merge;
012  use function basename;
013  use function file_exists;
014  use function file_get_contents;
015  use function getcwd;
016  use function iterator_to_array;
017  use function json_decode;
018  use function json_encode;
019  use function sprintf;
020   
021  /**
022   * @internal
023   *
024   * This is a fallback for {@see \PackageVersions\Versions::getVersion()}
025   * Do not use this class directly: it is intended to be only used when
026   * {@see \PackageVersions\Versions} fails to be generated, which typically
027   * happens when running composer with `--no-scripts` flag)
028   */
029  final class FallbackVersions
030  {
031      const ROOT_PACKAGE_NAME = 'unknown/root-package@UNKNOWN';
032   
033      private function __construct()
034      {
035      }
036   
037      /**
038       * @throws OutOfBoundsException If a version cannot be located.
039       * @throws UnexpectedValueException If the composer.lock file could not be located.
040       */
041      public static function getVersion(string $packageName): string
042      {
043          $versions = iterator_to_array(self::getVersions(self::getPackageData()));
044   
045          if (! array_key_exists($packageName, $versions)) {
046              throw new OutOfBoundsException(
047                  'Required package "' . $packageName . '" is not installed: check your ./vendor/composer/installed.json and/or ./composer.lock files'
048              );
049          }
050   
051          return $versions[$packageName];
052      }
053   
054      /**
055       * @return mixed[]
056       *
057       * @throws UnexpectedValueException
058       */
059      private static function getPackageData(): array
060      {
061          $checkedPaths = [
062              // The top-level project's ./vendor/composer/installed.json
063              getcwd() . '/vendor/composer/installed.json',
064              __DIR__ . '/../../../../composer/installed.json',
065              // The top-level project's ./composer.lock
066              getcwd() . '/composer.lock',
067              __DIR__ . '/../../../../../composer.lock',
068              // This package's composer.lock
069              __DIR__ . '/../../composer.lock',
070          ];
071   
072          $packageData = [];
073          foreach ($checkedPaths as $path) {
074              if (! file_exists($path)) {
075                  continue;
076              }
077   
078              $data = json_decode(file_get_contents($path), true);
079              switch (basename($path)) {
080                  case 'installed.json':
081                      // composer 2.x installed.json format
082                      if (isset($data['packages'])) {
083                          $packageData[] = $data['packages'];
084                      } else {
085                          // composer 1.x installed.json format
086                          $packageData[] = $data;
087                      }
088   
089                      break;
090                  case 'composer.lock':
091                      $packageData[] = $data['packages'] + ($data['packages-dev'] ?? []);
092                      break;
093                  default:
094                      // intentionally left blank
095              }
096          }
097   
098          if ($packageData !== []) {
099              return array_merge(...$packageData);
100          }
101   
102          throw new UnexpectedValueException(sprintf(
103              'PackageVersions could not locate the `vendor/composer/installed.json` or your `composer.lock` '
104              . 'location. This is assumed to be in %s. If you customized your composer vendor directory and ran composer '
105              . 'installation with --no-scripts, or if you deployed without the required composer files, PackageVersions '
106              . 'can\'t detect installed versions.',
107              json_encode($checkedPaths)
108          ));
109      }
110   
111      /**
112       * @param mixed[] $packageData
113       *
114       * @return Generator&string[]
115       *
116       * @psalm-return Generator<string, string>
117       */
118      private static function getVersions(array $packageData): Generator
119      {
120          foreach ($packageData as $package) {
121              yield $package['name'] => $package['version'] . '@' . (
122                  $package['source']['reference'] ?? $package['dist']['reference'] ?? ''
123              );
124          }
125   
126          yield self::ROOT_PACKAGE_NAME => self::ROOT_PACKAGE_NAME;
127      }
128  }
129