‪TYPO3CMS  11.5
ComposerDeficitDetector.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 
27 {
30  public const ‪EXTENSION_KEY_MISSING = 2;
31 
32  private array ‪$availableExtensions;
33 
34  public function ‪__construct(‪ListUtility $listUtility)
35  {
36  $this->availableExtensions = $listUtility->‪getAvailableExtensions('Local');
37  }
38 
42  public function ‪getExtensionsWithComposerDeficit(): array
43  {
44  $extensionsWithDeficit = [];
45  foreach ($this->availableExtensions as $extensionKey => $extensionInformation) {
46  $extensionComposerDeficit = $this->‪checkExtensionComposerDeficit($extensionKey);
47  if ($extensionComposerDeficit !== self::EXTENSION_COMPOSER_MANIFEST_VALID) {
48  $extensionsWithDeficit[$extensionKey] = $extensionInformation;
49  $extensionsWithDeficit[$extensionKey]['deficit'] = $extensionComposerDeficit;
50  }
51  }
52 
53  return $extensionsWithDeficit;
54  }
55 
59  public function ‪checkExtensionComposerDeficit(string $extensionKey): int
60  {
61  if (empty($this->availableExtensions[$extensionKey])) {
62  throw new \InvalidArgumentException('Extension key ' . $extensionKey . ' is not valid.', 1619446378);
63  }
64 
65  $composerManifestPath = $this->availableExtensions[$extensionKey]['packagePath'] . 'composer.json';
66 
67  if (!file_exists($composerManifestPath) || !($composerManifest = file_get_contents($composerManifestPath))) {
69  }
70 
71  $composerManifest = json_decode($composerManifest, true) ?? [];
72 
73  if (!is_array($composerManifest) || $composerManifest === []) {
74  // Treat empty or invalid composer.json as missing
76  }
77 
78  return empty($composerManifest['extra']['typo3/cms']['extension-key'])
81  }
82 }
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\getAvailableExtensions
‪array[] getAvailableExtensions(string $filter='')
Definition: ListUtility.php:108
‪TYPO3\CMS\Extensionmanager\Package\ComposerDeficitDetector
Definition: ComposerDeficitDetector.php:27
‪TYPO3\CMS\Extensionmanager\Package\ComposerDeficitDetector\EXTENSION_COMPOSER_MANIFEST_MISSING
‪const EXTENSION_COMPOSER_MANIFEST_MISSING
Definition: ComposerDeficitDetector.php:29
‪TYPO3\CMS\Extensionmanager\Package\ComposerDeficitDetector\__construct
‪__construct(ListUtility $listUtility)
Definition: ComposerDeficitDetector.php:34
‪TYPO3\CMS\Extensionmanager\Package
Definition: ComposerDeficitDetector.php:18
‪TYPO3\CMS\Extensionmanager\Package\ComposerDeficitDetector\EXTENSION_COMPOSER_MANIFEST_VALID
‪const EXTENSION_COMPOSER_MANIFEST_VALID
Definition: ComposerDeficitDetector.php:28
‪TYPO3\CMS\Extensionmanager\Package\ComposerDeficitDetector\checkExtensionComposerDeficit
‪checkExtensionComposerDeficit(string $extensionKey)
Definition: ComposerDeficitDetector.php:59
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility
Definition: ListUtility.php:40
‪TYPO3\CMS\Extensionmanager\Package\ComposerDeficitDetector\getExtensionsWithComposerDeficit
‪getExtensionsWithComposerDeficit()
Definition: ComposerDeficitDetector.php:42
‪TYPO3\CMS\Extensionmanager\Package\ComposerDeficitDetector\EXTENSION_KEY_MISSING
‪const EXTENSION_KEY_MISSING
Definition: ComposerDeficitDetector.php:30
‪TYPO3\CMS\Extensionmanager\Package\ComposerDeficitDetector\$availableExtensions
‪array $availableExtensions
Definition: ComposerDeficitDetector.php:32