TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ClassNamingUtility.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Utility;
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 
25 {
34  public static function translateModelNameToRepositoryName($modelName)
35  {
36  return str_replace(
37  ['\\Domain\\Model', '_Domain_Model_'],
38  ['\\Domain\\Repository', '_Domain_Repository_'],
39  $modelName
40  ) . 'Repository';
41  }
42 
51  public static function translateModelNameToValidatorName($modelName)
52  {
53  return str_replace(
54  ['\\Domain\\Model\\', '_Domain_Model_'],
55  ['\\Domain\\Validator\\', '_Domain_Validator_'],
56  $modelName
57  ) . 'Validator';
58  }
59 
68  public static function translateRepositoryNameToModelName($repositoryName)
69  {
70  return preg_replace(
71  ['/\\\\Domain\\\\Repository/', '/_Domain_Repository_/', '/Repository$/'],
72  ['\\Domain\\Model', '_Domain_Model_', ''],
73  $repositoryName
74  );
75  }
76 
84  public static function explodeObjectControllerName($controllerObjectName)
85  {
86  $matches = [];
87 
88  if (strpos($controllerObjectName, '\\') !== false) {
89  if (substr($controllerObjectName, 0, 9) === 'TYPO3\\CMS') {
90  $extensionName = '^(?P<vendorName>[^\\\\]+\\\[^\\\\]+)\\\(?P<extensionName>[^\\\\]+)';
91  } else {
92  $extensionName = '^(?P<vendorName>[^\\\\]+)\\\\(?P<extensionName>[^\\\\]+)';
93  }
94 
95  preg_match(
96  '/' . $extensionName . '\\\\(Controller|Command|(?P<subpackageKey>.+)\\\\Controller)\\\\(?P<controllerName>[a-z\\\\]+)Controller$/ix',
97  $controllerObjectName,
98  $matches
99  );
100  } else {
101  preg_match(
102  '/^Tx_(?P<extensionName>[^_]+)_(Controller|Command|(?P<subpackageKey>.+)_Controller)_(?P<controllerName>[a-z_]+)Controller$/ix',
103  $controllerObjectName,
104  $matches
105  );
106  }
107 
108  return $matches;
109  }
110 }
static explodeObjectControllerName($controllerObjectName)
static translateRepositoryNameToModelName($repositoryName)