2 namespace TYPO3\CMS\Core\Utility
;
4 /***************************************************************
7 * (c) 2012-2013 Extbase Team
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
30 * Several functions related to naming and convertions of names
31 * such as translation between Repository and Model names or
32 * exploding an objectControllerName into pieces
36 class ClassNamingUtility
{
39 * Translates a model name to an appropriate repository name
40 * e.g. Tx_Extbase_Domain_Model_Foo to Tx_Extbase_Domain_Repository_FooRepository
41 * or \TYPO3\CMS\Extbase\Domain\Model\Foo to \TYPO3\CMS\Extbase\Domain\Repository\FooRepository
43 * @param string $modelName Name of the model to translate
44 * @return string Name of the repository
46 static public function translateModelNameToRepositoryName($modelName) {
48 array('\\Domain\\Model', '_Domain_Model_'),
49 array('\\Domain\\Repository', '_Domain_Repository_'),
55 * Translates a model name to an appropriate validator name
56 * e.g. Tx_Extbase_Domain_Model_Foo to Tx_Extbase_Domain_Validator_FooValidator
57 * or \TYPO3\CMS\Extbase\Domain\Model\Foo to \TYPO3\CMS\Extbase\Domain\Validator\FooValidator
59 * @param string $modelName Name of the model to translate
60 * @return string Name of the repository
62 static public function translateModelNameToValidatorName($modelName) {
64 array('\\Domain\\Model\\', '_Domain_Model_'),
65 array('\\Domain\\Validator\\', '_Domain_Validator_'),
71 * Translates a repository name to an appropriate model name
72 * e.g. Tx_Extbase_Domain_Repository_FooRepository to Tx_Extbase_Domain_Model_Foo
73 * or \TYPO3\CMS\Extbase\Domain\Repository\FooRepository to \TYPO3\CMS\Extbase\Domain\Model\Foo
75 * @param string $repositoryName Name of the repository to translate
76 * @return string Name of the model
78 static public function translateRepositoryNameToModelName($repositoryName) {
80 array('/\\\\Domain\\\\Repository/', '/_Domain_Repository_/', '/Repository$/'),
81 array('\\Domain\\Model', '_Domain_Model_', ''),
89 * Explodes a controllerObjectName like \Vendor\Ext\Controller\FooController
90 * into several pieces like vendorName, extensionName, subpackageKey and controllerName
92 * @param string $controllerObjectName The controller name to be exploded
93 * @return array An array of controllerObjectName pieces
95 static public function explodeObjectControllerName($controllerObjectName) {
98 if (strpos($controllerObjectName, '\\') !== FALSE) {
99 if (substr($controllerObjectName, 0, 9) === 'TYPO3\\CMS') {
100 $extensionName = '^(?P<vendorName>[^\\\\]+\\\[^\\\\]+)\\\(?P<extensionName>[^\\\\]+)';
102 $extensionName = '^(?P<vendorName>[^\\\\]+)\\\\(?P<extensionName>[^\\\\]+)';
106 '/' . $extensionName . '\\\\(Controller|Command|(?P<subpackageKey>.+)\\\\Controller)\\\\(?P<controllerName>[a-z\\\\]+)Controller$/ix',
107 $controllerObjectName,
112 '/^Tx_(?P<extensionName>[^_]+)_(Controller|Command|(?P<subpackageKey>.+)_Controller)_(?P<controllerName>[a-z_]+)Controller$/ix',
113 $controllerObjectName,