TYPO3 CMS  TYPO3_8-7
CommandRequestHandler.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Console;
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 
25 
30 {
35  protected $bootstrap;
36 
41  protected $application;
42 
48  public function __construct(Bootstrap $bootstrap)
49  {
50  $this->bootstrap = $bootstrap;
51  $this->application = new Application('TYPO3 CMS', TYPO3_version);
52  }
53 
59  public function handleRequest(InputInterface $input)
60  {
61  $output = new ConsoleOutput();
62 
63  $this->bootstrap
64  ->loadBaseTca()
65  ->loadExtTables()
66  // create the BE_USER object (not logged in yet)
67  ->initializeBackendUser(CommandLineUserAuthentication::class)
68  ->initializeLanguageObject()
69  // Make sure output is not buffered, so command-line output and interaction can take place
70  ->endOutputBufferingAndCleanPreviousOutput();
71 
72  $this->populateAvailableCommands();
73 
74  // Check if the command to run needs a backend user to be loaded
75  $command = $this->getCommandToRun($input);
76 
77  if (!$command) {
78  // Using old "cliKeys" is marked as deprecated and will be removed in TYPO3 v9
79  $cliKeys = array_keys($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys']);
80 
81  $output->writeln('Using old "cliKeys" ($GLOBALS[TYPO3_CONF_VARS][SC_OPTIONS][GLOBAL][cliKeys]) is marked as deprecated and will be removed in TYPO3 v9:');
82  $output->writeln('Old entrypoint keys available:');
83  asort($cliKeys);
84  foreach ($cliKeys as $key => $value) {
85  $output->writeln(' ' . $value);
86  }
87  $output->writeln('');
88  $output->writeln('TYPO3 Console Commands:');
89  }
90 
91  $exitCode = $this->application->run($input, $output);
92  exit($exitCode);
93  }
94 
101  public function canHandleRequest(InputInterface $input)
102  {
103  return true;
104  }
105 
111  public function getPriority()
112  {
113  return 50;
114  }
115 
120  protected function getCommandToRun(InputInterface $input)
121  {
122  $firstArgument = $input->getFirstArgument();
123  try {
124  return $this->application->find($firstArgument);
125  } catch (\InvalidArgumentException $e) {
126  return false;
127  }
128  }
129 
133  protected function populateAvailableCommands()
134  {
136  $packageManager = Bootstrap::getInstance()->getEarlyInstance(PackageManager::class);
137 
138  foreach ($packageManager->getActivePackages() as $package) {
139  $commandsOfExtension = $package->getPackagePath() . 'Configuration/Commands.php';
140  if (@is_file($commandsOfExtension)) {
141  $commands = require_once $commandsOfExtension;
142  if (is_array($commands)) {
143  foreach ($commands as $commandName => $commandDescription) {
145  $cmd = GeneralUtility::makeInstance($commandDescription['class'], $commandName);
146  // Check if the command name is already in use
147  if ($this->application->has($commandName)) {
148  throw new CommandNameAlreadyInUseException('Command "' . $commandName . '" registered by "' . $package->getPackageKey() . '" is already in use', 1484486383);
149  }
150  $this->application->add($cmd);
151  }
152  }
153  }
154  }
155  }
156 }
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']