3 declare(strict_types
=1);
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 require __DIR__
. '/../../vendor/autoload.php';
19 if (PHP_SAPI
!== 'cli') {
20 die('Script must be called from command line.' . chr(10));
24 * Core integrity test script:
26 * Find all composer.json files in all system extensions and compare
27 * their dependencies against the defined dependencies of our root
30 class checkIntegrityComposer
35 private $rootComposerJson = [];
37 private $testResults = [];
40 * Executes the composer integrity check.
41 * The return value is used directly in the ext() call outside this class.
45 public function execute(): int
47 $rootComposerJson = __DIR__
. '/../../composer.json';
48 $this->rootComposerJson
= json_decode(file_get_contents($rootComposerJson), true);
49 $filesToProcess = $this->findExtensionComposerJson();
50 $output = new \Symfony\Component\Console\Output\
ConsoleOutput();
52 $resultAcrossAllFiles = 0;
53 /** @var \SplFileInfo $composerJsonFile */
54 foreach ($filesToProcess as $composerJsonFile) {
55 $fullFilePath = $composerJsonFile->getRealPath();
56 $this->validateComposerJson($fullFilePath);
58 if (!empty($this->testResults
)) {
59 $table = new \Symfony\Component\Console\Helper\
Table($output);
67 foreach ($this->testResults
as $extKey => $results) {
68 foreach ($results as $result) {
72 $result['dependency'],
79 $resultAcrossAllFiles = 1;
81 return $resultAcrossAllFiles;
85 * Finds all composer.json files in TYPO3s system extensions
87 * @return \Symfony\Component\Finder\Finder
89 private function findExtensionComposerJson(): \Symfony\Component\Finder\Finder
91 $finder = new Symfony\Component\Finder\
Finder();
92 $composerFiles = $finder
94 ->in(__DIR__
. '/../../typo3/sysext/*')
95 ->name('composer.json');
96 return $composerFiles;
100 * Checks if the dependencies defined in $composerJsonFile are the same as
101 * in TYPO3s root composer.json file.
103 * @param string $composerJsonFile
105 private function validateComposerJson(string $composerJsonFile)
107 $extensionKey = $this->extractExtensionKey($composerJsonFile);
108 $extensionComposerJson = json_decode(file_get_contents($composerJsonFile), true);
109 // Check require section
110 foreach ($this->rootComposerJson
['require'] as $requireKey => $requireItem) {
111 if (isset($extensionComposerJson['require'][$requireKey]) && $extensionComposerJson['require'][$requireKey] !== $requireItem) {
113 $this->testResults
[$extensionKey][] = [
115 'dependency' => $requireKey,
116 'shouldBe' => $requireItem,
117 'actuallyIs' => $extensionComposerJson['require'][$requireKey]
121 // Check require-dev section
122 foreach ($this->rootComposerJson
['require-dev'] as $requireDevKey => $requireDevItem) {
123 if (isset($extensionComposerJson['require-dev'][$requireDevKey]) && $extensionComposerJson['require-dev'][$requireDevKey] !== $requireDevItem) {
125 $this->testResults
[$extensionKey][] = [
126 'type' => 'require-dev',
127 'dependency' => $requireDevKey,
128 'shouldBe' => $requireDevItem,
129 'actuallyIs' => $extensionComposerJson['require-dev'][$requireDevKey]
136 * Makes the output on CLI a bit more readable
138 * @param string $filename
141 private function extractExtensionKey(string $filename): string
143 $pattern = '/typo3\/sysext\/(?<extName>[a-z].+?)\//';
144 preg_match_all($pattern, $filename, $matches, PREG_SET_ORDER
, 0);
145 return $matches[0]['extName'];
149 $composerIntegrityChecker = new checkIntegrityComposer();
150 exit($composerIntegrityChecker->execute());