TYPO3 CMS  TYPO3_6-2
MenuContentObjectFactory.php
Go to the documentation of this file.
1 <?php
3 
25 
31  protected $menuTypeToClassMapping = array(
32  'GMENU' => 'TYPO3\\CMS\\Frontend\\ContentObject\\Menu\\GraphicalMenuContentObject',
33  'TMENU' => 'TYPO3\\CMS\\Frontend\\ContentObject\\Menu\\TextMenuContentObject',
34  'IMGMENU' => 'TYPO3\\CMS\\Frontend\\ContentObject\\Menu\\ImageMenuContentObject',
35  'JSMENU' => 'TYPO3\\CMS\\Frontend\\ContentObject\\Menu\\JavaScriptMenuContentObject',
36  );
37 
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 {
51  'Menu type ' . (string)$type . ' has no implementing class.',
52  1363278130
53  );
54  }
55  return $object;
56  }
57 
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 }