TYPO3  7.6
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  array('\\Domain\\Model', '_Domain_Model_'),
38  array('\\Domain\\Repository', '_Domain_Repository_'),
39  $modelName
40  ) . 'Repository';
41  }
42 
51  public static function translateModelNameToValidatorName($modelName)
52  {
53  return str_replace(
54  array('\\Domain\\Model\\', '_Domain_Model_'),
55  array('\\Domain\\Validator\\', '_Domain_Validator_'),
56  $modelName
57  ) . 'Validator';
58  }
59 
68  public static function translateRepositoryNameToModelName($repositoryName)
69  {
70  return preg_replace(
71  array('/\\\\Domain\\\\Repository/', '/_Domain_Repository_/', '/Repository$/'),
72  array('\\Domain\\Model', '_Domain_Model_', ''),
73  $repositoryName
74  );
75  }
76 
77 
78 
86  public static function explodeObjectControllerName($controllerObjectName)
87  {
88  $matches = array();
89 
90  if (strpos($controllerObjectName, '\\') !== false) {
91  if (substr($controllerObjectName, 0, 9) === 'TYPO3\\CMS') {
92  $extensionName = '^(?P<vendorName>[^\\\\]+\\\[^\\\\]+)\\\(?P<extensionName>[^\\\\]+)';
93  } else {
94  $extensionName = '^(?P<vendorName>[^\\\\]+)\\\\(?P<extensionName>[^\\\\]+)';
95  }
96 
97  preg_match(
98  '/' . $extensionName . '\\\\(Controller|Command|(?P<subpackageKey>.+)\\\\Controller)\\\\(?P<controllerName>[a-z\\\\]+)Controller$/ix',
99  $controllerObjectName,
100  $matches
101  );
102  } else {
103  preg_match(
104  '/^Tx_(?P<extensionName>[^_]+)_(Controller|Command|(?P<subpackageKey>.+)_Controller)_(?P<controllerName>[a-z_]+)Controller$/ix',
105  $controllerObjectName,
106  $matches
107  );
108  }
109 
110  return $matches;
111  }
112 }