TYPO3 CMS  TYPO3_6-2
CommandManager.php
Go to the documentation of this file.
1 <?php
3 
22 
27  protected $objectManager;
28 
32  protected $availableCommands = NULL;
33 
37  protected $shortCommandIdentifiers = NULL;
38 
45  public function getAvailableCommands() {
46  if ($this->availableCommands === NULL) {
47  $this->availableCommands = array();
48  $commandControllerClassNames = is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers']) ? $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'] : array();
49  foreach ($commandControllerClassNames as $className) {
50  if (!class_exists($className)) {
51  continue;
52  }
53  foreach (get_class_methods($className) as $methodName) {
54  if (substr($methodName, -7, 7) === 'Command') {
55  $this->availableCommands[] = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Command', $className, substr($methodName, 0, -7));
56  }
57  }
58  }
59  }
61  }
62 
74  public function getCommandByIdentifier($commandIdentifier) {
75  $commandIdentifier = strtolower(trim($commandIdentifier));
76  if ($commandIdentifier === 'help') {
77  $commandIdentifier = 'extbase:help:help';
78  }
79  $matchedCommands = array();
81  foreach ($availableCommands as $command) {
82  if ($this->commandMatchesIdentifier($command, $commandIdentifier)) {
83  $matchedCommands[] = $command;
84  }
85  }
86  if (count($matchedCommands) === 0) {
87  throw new \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchCommandException('No command could be found that matches the command identifier "' . $commandIdentifier . '".', 1310556663);
88  }
89  if (count($matchedCommands) > 1) {
90  throw new \TYPO3\CMS\Extbase\Mvc\Exception\AmbiguousCommandIdentifierException('More than one command matches the command identifier "' . $commandIdentifier . '"', 1310557169, NULL, $matchedCommands);
91  }
92  return current($matchedCommands);
93  }
94 
102  public function getShortestIdentifierForCommand(\TYPO3\CMS\Extbase\Mvc\Cli\Command $command) {
103  if ($command->getCommandIdentifier() === 'extbase:help:help') {
104  return 'help';
105  }
107  if (!isset($shortCommandIdentifiers[$command->getCommandIdentifier()])) {
108  $command->getCommandIdentifier();
109  }
110  return $shortCommandIdentifiers[$command->getCommandIdentifier()];
111  }
112 
118  protected function getShortCommandIdentifiers() {
119  if ($this->shortCommandIdentifiers === NULL) {
120  $commandsByCommandName = array();
121  foreach ($this->getAvailableCommands() as $availableCommand) {
122  list($extensionKey, $controllerName, $commandName) = explode(':', $availableCommand->getCommandIdentifier());
123  if (!isset($commandsByCommandName[$commandName])) {
124  $commandsByCommandName[$commandName] = array();
125  }
126  if (!isset($commandsByCommandName[$commandName][$controllerName])) {
127  $commandsByCommandName[$commandName][$controllerName] = array();
128  }
129  $commandsByCommandName[$commandName][$controllerName][] = $extensionKey;
130  }
131  foreach ($this->getAvailableCommands() as $availableCommand) {
132  list($extensionKey, $controllerName, $commandName) = explode(':', $availableCommand->getCommandIdentifier());
133  if (count($commandsByCommandName[$commandName][$controllerName]) > 1) {
134  $this->shortCommandIdentifiers[$availableCommand->getCommandIdentifier()] = sprintf('%s:%s:%s', $extensionKey, $controllerName, $commandName);
135  } else {
136  $this->shortCommandIdentifiers[$availableCommand->getCommandIdentifier()] = sprintf('%s:%s', $controllerName, $commandName);
137  }
138  }
139  }
141  }
142 
151  protected function commandMatchesIdentifier(\TYPO3\CMS\Extbase\Mvc\Cli\Command $command, $commandIdentifier) {
152  $commandIdentifierParts = explode(':', $command->getCommandIdentifier());
153  $searchedCommandIdentifierParts = explode(':', $commandIdentifier);
154  $extensionKey = array_shift($commandIdentifierParts);
155  if (count($searchedCommandIdentifierParts) === 3) {
156  $searchedExtensionKey = array_shift($searchedCommandIdentifierParts);
157  if ($searchedExtensionKey !== $extensionKey) {
158  return FALSE;
159  }
160  }
161  if (count($searchedCommandIdentifierParts) !== 2) {
162  return FALSE;
163  }
164  return $searchedCommandIdentifierParts === $commandIdentifierParts;
165  }
166 }
commandMatchesIdentifier(\TYPO3\CMS\Extbase\Mvc\Cli\Command $command, $commandIdentifier)
getShortestIdentifierForCommand(\TYPO3\CMS\Extbase\Mvc\Cli\Command $command)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]