[CLEANUP] Improve the @param/@return/@var PHPDoc
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / Menu / MenuContentObjectFactory.php
1 <?php
2 namespace TYPO3\CMS\Frontend\ContentObject\Menu;
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
17 /**
18 * Factory for menu content objects. Allows overriding the default
19 * types like 'GMENU' with an own implementation (only one possible)
20 * and new types can be registered.
21 *
22 * @author Christian Kuhn <lolli@schwarzbu.ch>
23 */
24 class MenuContentObjectFactory implements \TYPO3\CMS\Core\SingletonInterface {
25
26 /**
27 * Register of TypoScript keys to according render class
28 *
29 * @var array
30 */
31 protected $menuTypeToClassMapping = array(
32 'GMENU' => \TYPO3\CMS\Frontend\ContentObject\Menu\GraphicalMenuContentObject::class,
33 'TMENU' => \TYPO3\CMS\Frontend\ContentObject\Menu\TextMenuContentObject::class,
34 'IMGMENU' => \TYPO3\CMS\Frontend\ContentObject\Menu\ImageMenuContentObject::class,
35 'JSMENU' => \TYPO3\CMS\Frontend\ContentObject\Menu\JavaScriptMenuContentObject::class,
36 );
37
38 /**
39 * Gets a typo script string like 'TMENU' and returns an object of this type
40 *
41 * @param string $type
42 * @return AbstractMenuContentObject Menu object
43 * @throws Exception\NoSuchMenuTypeException
44 */
45 public function getMenuObjectByType($type = '') {
46 $uppercasedClassname = strtoupper($type);
47 if (array_key_exists($uppercasedClassname, $this->menuTypeToClassMapping)) {
48 $object = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($this->menuTypeToClassMapping[$uppercasedClassname]);
49 } else {
50 throw new Exception\NoSuchMenuTypeException(
51 'Menu type ' . (string)$type . ' has no implementing class.',
52 1363278130
53 );
54 }
55 return $object;
56 }
57
58 /**
59 * Register new menu type or override existing type
60 *
61 * @param string $type Menu type to be used in TypoScript
62 * @param string $className Class rendering the menu
63 * @throws \InvalidArgumentException
64 */
65 public function registerMenuType($type, $className) {
66 if (!is_string($type) || !is_string($className)) {
67 throw new \InvalidArgumentException(
68 'type and className must be strings',
69 1363429303
70 );
71 }
72 $this->menuTypeToClassMapping[strtoupper($type)] = $className;
73 }
74
75 }