‪TYPO3CMS  ‪main
ClassNamingUtility.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 
21 
28 {
34  public static function ‪translateModelNameToRepositoryName(string $modelName): string
35  {
36  return str_replace(
37  '\\Domain\\Model',
38  '\\Domain\\Repository',
39  $modelName
40  ) . 'Repository';
41  }
42 
52  public static function ‪translateRepositoryNameToModelName(string $repositoryName): string
53  {
54  return preg_replace(
55  ['/\\\\Domain\\\\Repository/', '/Repository$/'],
56  ['\\Domain\\Model', ''],
57  $repositoryName
58  );
59  }
60 
68  public static function ‪explodeObjectControllerName(string $controllerObjectName): array
69  {
70  $matches = [];
71  $extensionName = str_starts_with($controllerObjectName, 'TYPO3\\CMS')
72  ? '^(?P<vendorName>[^\\\\]+\\\[^\\\\]+)\\\‍(?P<extensionName>[^\\\\]+)'
73  : '^(?P<vendorName>[^\\\\]+)\\\\(?P<extensionName>[^\\\\]+)';
74  preg_match(
75  '/' . $extensionName . '\\\\(Controller|Command|(?P<subpackageKey>.+)\\\\Controller)\\\\(?P<controllerName>[a-z\\\\]+)Controller$/ix',
76  $controllerObjectName,
77  $matches
78  );
79  return array_filter($matches, is_string(...), ARRAY_FILTER_USE_KEY);
80  }
81 }
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\translateRepositoryNameToModelName
‪static class string translateRepositoryNameToModelName(string $repositoryName)
Definition: ClassNamingUtility.php:52
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\translateModelNameToRepositoryName
‪static translateModelNameToRepositoryName(string $modelName)
Definition: ClassNamingUtility.php:34
‪TYPO3\CMS\Core\Utility
Definition: ArrayUtility.php:18
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\explodeObjectControllerName
‪static array< string > explodeObjectControllerName(string $controllerObjectName)
Definition: ClassNamingUtility.php:68
‪TYPO3\CMS\Extbase\Persistence\RepositoryInterface
Definition: RepositoryInterface.php:25
‪TYPO3\CMS\Core\Utility\ClassNamingUtility
Definition: ClassNamingUtility.php:28