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
61 * @return string Name of the repository
63 static public function translateModelNameToValidatorName($modelName) {
65 array('\\Domain\\Model\\', '_Domain_Model_'),
66 array('\\Domain\\Validator\\', '_Domain_Validator_'),
72 * Translates a repository name to an appropriate model name
73 * e.g. Tx_Extbase_Domain_Repository_FooRepository to Tx_Extbase_Domain_Model_Foo
74 * or \TYPO3\CMS\Extbase\Domain\Repository\FooRepository to \TYPO3\CMS\Extbase\Domain\Model\Foo
76 * @param string $repositoryName Name of the repository to translate
77 * @return string Name of the model
79 static public function translateRepositoryNameToModelName($repositoryName) {
81 array('/\\\Domain\\\Repository/', '/Domain_Repository/', '/Repository$/'),
82 array('\\Domain\\Model', 'Domain_Model', ''),
90 * Explodes a controllerObjectName like \Vendor\Ext\Controller\FooController
91 * into several pieces like vendorName, extensionName, subpackageKey and controllerName
93 * @param string $controllerObjectName The controller name to be exploded
94 * @return array An array of controllerObjectName pieces
96 static public function explodeObjectControllerName($controllerObjectName) {
99 if (strpos($controllerObjectName, '\\') !== FALSE) {
100 if (substr($controllerObjectName, 0, 9) === 'TYPO3\CMS') {
101 $extensionName = '^(?P<vendorName>[^\\\]+\\\[^\\\]+)\\\(?P<extensionName>[^\\\]+)';
103 $extensionName = '^(?P<vendorName>[^\\\]+)\\\(?P<extensionName>[^\\\]+)';
107 '/' . $extensionName . '\\\(Controller|Command|(?P<subpackageKey>.+)\\\Controller)\\\(?P<controllerName>[a-z\\\]+)Controller$/ix',
108 $controllerObjectName,
113 '/^Tx_(?P<extensionName>[^_]+)_(Controller|Command|(?P<subpackageKey>.+)_Controller)_(?P<controllerName>[a-z_]+)Controller$/ix',
114 $controllerObjectName,