‪TYPO3CMS  10.4
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 
20 use Symfony\Component\Finder\Finder;
23 
29 {
32  public const ‪EXTENSION_KEY_MISSING = 2;
33 
37  public function ‪getExtensionsWithComposerDeficit(): array
38  {
39  ‪$finder = Finder::create()->directories()->depth(0)->in(‪Environment::getExtensionsPath());
40  $extensionsWithDeficit = [];
41 
42  if (‪$finder->hasResults()) {
43  foreach (‪$finder as $extensionFolder) {
44  $extensionKey = $extensionFolder->getFilename();
45  try {
46  $extensionComposerDeficit = $this->‪checkExtensionComposerDeficit($extensionKey);
47  } catch (\InvalidArgumentException $e) {
48  // Skip invalid extensions
49  continue;
50  }
51  if ($extensionComposerDeficit !== self::EXTENSION_COMPOSER_MANIFEST_VALID) {
52  $extensionsWithDeficit[$extensionKey] = $extensionComposerDeficit;
53  }
54  }
55  }
56 
57  return $extensionsWithDeficit;
58  }
59 
63  public function ‪checkExtensionComposerDeficit(string $extensionKey): int
64  {
65  if (!$this->‪isValidExtensionKey($extensionKey)) {
66  throw new \InvalidArgumentException('Extension key ' . $extensionKey . ' is not valid.', 1619446378);
67  }
68 
69  $composerManifestPath = ‪Environment::getExtensionsPath() . '/' . $extensionKey . '/composer.json';
70 
71  if (!file_exists($composerManifestPath) || !($composerManifest = file_get_contents($composerManifestPath))) {
73  }
74 
75  $composerManifest = json_decode($composerManifest, true) ?? [];
76 
77  if (!is_array($composerManifest) || $composerManifest === []) {
78  // Treat empty or invalid composer.json as missing
80  }
81 
82  return empty($composerManifest['extra']['typo3/cms']['extension-key'])
85  }
86 
87  protected function ‪isValidExtensionKey(string $extensionKey): bool
88  {
89  return preg_match('/^[0-9a-z._\-]+$/i', $extensionKey)
90  && GeneralUtility::isAllowedAbsPath(‪Environment::getExtensionsPath() . '/' . $extensionKey);
91  }
92 }
‪TYPO3\CMS\Core\Package\ComposerDeficitDetector\getExtensionsWithComposerDeficit
‪getExtensionsWithComposerDeficit()
Definition: ComposerDeficitDetector.php:37
‪TYPO3\CMS\Core\Package\ComposerDeficitDetector\EXTENSION_COMPOSER_MANIFEST_VALID
‪const EXTENSION_COMPOSER_MANIFEST_VALID
Definition: ComposerDeficitDetector.php:30
‪TYPO3\CMS\Core\Package\ComposerDeficitDetector\checkExtensionComposerDeficit
‪checkExtensionComposerDeficit(string $extensionKey)
Definition: ComposerDeficitDetector.php:63
‪$finder
‪if(PHP_SAPI !=='cli') $finder
Definition: header-comment.php:22
‪TYPO3\CMS\Core\Package\ComposerDeficitDetector
Definition: ComposerDeficitDetector.php:29
‪TYPO3\CMS\Core\Package\ComposerDeficitDetector\EXTENSION_KEY_MISSING
‪const EXTENSION_KEY_MISSING
Definition: ComposerDeficitDetector.php:32
‪TYPO3\CMS\Core\Package\ComposerDeficitDetector\EXTENSION_COMPOSER_MANIFEST_MISSING
‪const EXTENSION_COMPOSER_MANIFEST_MISSING
Definition: ComposerDeficitDetector.php:31
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Core\Package
Definition: AbstractServiceProvider.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Package\ComposerDeficitDetector\isValidExtensionKey
‪isValidExtensionKey(string $extensionKey)
Definition: ComposerDeficitDetector.php:87
‪TYPO3\CMS\Core\Core\Environment\getExtensionsPath
‪static string getExtensionsPath()
Definition: Environment.php:271