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