[BUGFIX] Fix several typos in php comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / ClassesConfiguration.php
1 <?php
2 declare(strict_types = 1);
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
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.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 namespace TYPO3\CMS\Extbase\Persistence;
17
18 /**
19 * Class TYPO3\CMS\Extbase\Persistence\ClassesConfiguration
20 */
21 class ClassesConfiguration
22 {
23 /**
24 * @var array
25 */
26 private $configuration;
27
28 /**
29 * @param array $configuration
30 */
31 public function __construct(array $configuration)
32 {
33 $this->configuration = $configuration;
34 }
35
36 /**
37 * @param string $className
38 * @return bool
39 */
40 public function hasClass(string $className): bool
41 {
42 return array_key_exists($className, $this->configuration);
43 }
44
45 /**
46 * @param string $className
47 * @return array|null
48 */
49 public function getConfigurationFor(string $className): ?array
50 {
51 return $this->configuration[$className] ?? null;
52 }
53
54 /**
55 * Resolves all subclasses for the given set of (sub-)classes.
56 * The whole classes configuration is used to determine all subclasses recursively.
57 *
58 * @param string $className
59 * @return array A numeric array that contains all available subclasses-strings as values.
60 */
61 public function getSubClasses(string $className): array
62 {
63 return $this->resolveSubClassesRecursive($className);
64 }
65
66 /**
67 * @param string $className
68 * @param array $subClasses
69 * @return array
70 */
71 private function resolveSubClassesRecursive(string $className, array $subClasses = []): array
72 {
73 foreach ($this->configuration[$className]['subclasses'] ?? [] as $subclass) {
74 if (in_array($subclass, $subClasses, true)) {
75 continue;
76 }
77
78 $subClasses[] = $subclass;
79 $subClasses = $this->resolveSubClassesRecursive($subclass, $subClasses);
80 }
81
82 return $subClasses;
83 }
84 }