TYPO3 CMS  TYPO3_8-7
MenuContentObjectFactory.php
Go to the documentation of this file.
1 <?php
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 
19 
26 {
33  'GMENU' => GraphicalMenuContentObject::class,
34  'TMENU' => TextMenuContentObject::class,
35  'IMGMENU' => ImageMenuContentObject::class,
36  'JSMENU' => JavaScriptMenuContentObject::class,
37  ];
38 
46  public function getMenuObjectByType($type = '')
47  {
48  $upperCasedClassName = strtoupper($type);
49  if (array_key_exists($upperCasedClassName, $this->menuTypeToClassMapping)) {
50  $object = GeneralUtility::makeInstance($this->menuTypeToClassMapping[$upperCasedClassName]);
51  } else {
53  'Menu type ' . (string)$type . ' has no implementing class.',
54  1363278130
55  );
56  }
57  return $object;
58  }
59 
67  public function registerMenuType($type, $className)
68  {
69  if (!is_string($type) || !is_string($className)) {
70  throw new \InvalidArgumentException(
71  'type and className must be strings',
72  1363429303
73  );
74  }
75  $this->menuTypeToClassMapping[strtoupper($type)] = $className;
76  }
77 }
static makeInstance($className,... $constructorArguments)