‪TYPO3CMS  9.5
MatcherFactory.php
Go to the documentation of this file.
1 <?php
2 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 
18 use PhpParser\NodeVisitor;
21 
27 {
35  public function ‪createAll(array $matcherConfigurations)
36  {
37  $instances = [];
38  foreach ($matcherConfigurations as $matcherConfiguration) {
39  if (empty($matcherConfiguration['class'])) {
40  throw new \RuntimeException(
41  'Each matcher must have a class name',
42  1501415721
43  );
44  }
45 
46  if (empty($matcherConfiguration['configurationFile']) && !isset($matcherConfiguration['configurationArray'])) {
47  throw new \RuntimeException(
48  'Each matcher must have either a configurationFile or configurationArray defined',
49  1501416365
50  );
51  }
52 
53  if (isset($matcherConfiguration['configurationFile']) && isset($matcherConfiguration['configurationArray'])) {
54  throw new \RuntimeException(
55  'Having both a configurationFile and configurationArray is invalid',
56  1501419367
57  );
58  }
59 
60  $configuration = [];
61  if (isset($matcherConfiguration['configurationFile'])) {
62  $configuration = GeneralUtility::getFileAbsFileName($matcherConfiguration['configurationFile']);
63  if (empty($configuration) || !is_file($configuration)) {
64  throw new \RuntimeException(
65  'Configuration file ' . $matcherConfiguration['configurationFile'] . ' not found',
66  1501509605
67  );
68  }
69  $configuration = require $configuration;
70  if (!is_array($configuration)) {
71  throw new \RuntimeException(
72  'Configuration file ' . $matcherConfiguration['configurationFile'] . ' must return an array',
73  1501509548
74  );
75  }
76  }
77 
78  if (isset($matcherConfiguration['configurationArray'])) {
79  if (!is_array($matcherConfiguration['configurationArray'])) {
80  throw new \RuntimeException(
81  'Configuration array ' . $matcherConfiguration['configurationArray'] . ' must not be empty',
82  1501509738
83  );
84  }
85  $configuration = $matcherConfiguration['configurationArray'];
86  }
87 
88  $matcherInstance = new $matcherConfiguration['class']($configuration);
89  if (!$matcherInstance instanceof ‪CodeScannerInterface
90  || !$matcherInstance instanceof NodeVisitor) {
91  throw new \RuntimeException(
92  'Matcher ' . $matcherConfiguration['class'] . ' must implement CodeScannerInterface'
93  . ' and NodeVisitor',
94  1501510168
95  );
96  }
97  $instances[] = $matcherInstance;
98  }
99  return $instances;
100  }
101 }
‪TYPO3\CMS\Install\ExtensionScanner\Php\MatcherFactory\createAll
‪NodeVisitor &[] CodeScannerInterface[] createAll(array $matcherConfigurations)
Definition: MatcherFactory.php:35
‪TYPO3\CMS\Install\ExtensionScanner\Php
Definition: CodeStatistics.php:3
‪TYPO3\CMS\Install\ExtensionScanner\CodeScannerInterface
Definition: CodeScannerInterface.php:22
‪TYPO3\CMS\Install\ExtensionScanner\Php\MatcherFactory
Definition: MatcherFactory.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45