‪TYPO3CMS  9.5
ClassNamingUtility.php
Go to the documentation of this file.
1 <?php
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 
23 {
32  public static function ‪translateModelNameToRepositoryName($modelName)
33  {
34  return str_replace(
35  '\\Domain\\Model',
36  '\\Domain\\Repository',
37  $modelName
38  ) . 'Repository';
39  }
40 
49  public static function ‪translateModelNameToValidatorName($modelName)
50  {
51  return str_replace(
52  '\\Domain\\Model\\',
53  '\\Domain\\Validator\\',
54  $modelName
55  ) . 'Validator';
56  }
57 
66  public static function ‪translateRepositoryNameToModelName($repositoryName)
67  {
68  return preg_replace(
69  ['/\\\\Domain\\\\Repository/', '/Repository$/'],
70  ['\\Domain\\Model', ''],
71  $repositoryName
72  );
73  }
74 
82  public static function ‪explodeObjectControllerName($controllerObjectName)
83  {
84  $matches = [];
85 
86  if (strpos($controllerObjectName, 'TYPO3\\CMS') === 0) {
87  $extensionName = '^(?P<vendorName>[^\\\\]+\\\[^\\\\]+)\\\‍(?P<extensionName>[^\\\\]+)';
88  } else {
89  $extensionName = '^(?P<vendorName>[^\\\\]+)\\\\(?P<extensionName>[^\\\\]+)';
90  }
91 
92  preg_match(
93  '/' . $extensionName . '\\\\(Controller|Command|(?P<subpackageKey>.+)\\\\Controller)\\\\(?P<controllerName>[a-z\\\\]+)Controller$/ix',
94  $controllerObjectName,
95  $matches
96  );
97 
98  return array_filter($matches, 'is_string', ARRAY_FILTER_USE_KEY);
99  }
100 }
‪TYPO3\CMS\Core\Utility
Definition: ArrayUtility.php:2
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\translateModelNameToRepositoryName
‪static string translateModelNameToRepositoryName($modelName)
Definition: ClassNamingUtility.php:32
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\explodeObjectControllerName
‪static array explodeObjectControllerName($controllerObjectName)
Definition: ClassNamingUtility.php:82
‪TYPO3\CMS\Core\Utility\ClassNamingUtility
Definition: ClassNamingUtility.php:23
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\translateRepositoryNameToModelName
‪static string translateRepositoryNameToModelName($repositoryName)
Definition: ClassNamingUtility.php:66
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\translateModelNameToValidatorName
‪static string translateModelNameToValidatorName($modelName)
Definition: ClassNamingUtility.php:49