TYPO3 CMS  TYPO3_6-2
Command.php
Go to the documentation of this file.
1 <?php
3 
21 class Command {
22 
27  protected $objectManager;
28 
33 
38 
42  protected $commandIdentifier;
43 
48 
54  protected $extensionName;
55 
62  protected $reflectionService;
63 
72  $this->controllerClassName = $controllerClassName;
73  $this->controllerCommandName = $controllerCommandName;
74  $delimiter = strpos($controllerClassName, '\\') !== FALSE ? '\\' : '_';
75  $classNameParts = explode($delimiter, $controllerClassName);
76  if (isset($classNameParts[0]) && $classNameParts[0] === 'TYPO3' && isset($classNameParts[1]) && $classNameParts[1] === 'CMS') {
77  $classNameParts[0] .= '\\' . $classNameParts[1];
78  unset($classNameParts[1]);
79  $classNameParts = array_values($classNameParts);
80  }
81  if (count($classNameParts) !== 4 || strpos($classNameParts[3], 'CommandController') === FALSE) {
82  throw new \InvalidArgumentException(
83  'Invalid controller class name "' . $controllerClassName . '". Class name must end with "CommandController".',
84  1305100019
85  );
86  }
87  $this->extensionName = $classNameParts[1];
89  $this->commandIdentifier = strtolower($extensionKey . ':' . substr($classNameParts[3], 0, -17) . ':' . $controllerCommandName);
90  }
91 
95  public function getControllerClassName() {
97  }
98 
102  public function getControllerCommandName() {
104  }
105 
111  public function getCommandIdentifier() {
113  }
114 
120  public function getExtensionName() {
121  return $this->extensionName;
122  }
123 
129  public function getShortDescription() {
130  $lines = explode(chr(10), $this->getCommandMethodReflection()->getDescription());
131  return count($lines) > 0 ? trim($lines[0]) : '<no description available>';
132  }
133 
141  public function getDescription() {
142  $lines = explode(chr(10), $this->getCommandMethodReflection()->getDescription());
143  array_shift($lines);
144  $descriptionLines = array();
145  foreach ($lines as $line) {
146  $trimmedLine = trim($line);
147  if ($descriptionLines !== array() || $trimmedLine !== '') {
148  $descriptionLines[] = $trimmedLine;
149  }
150  }
151  return implode(chr(10), $descriptionLines);
152  }
153 
159  public function hasArguments() {
160  return count($this->getCommandMethodReflection()->getParameters()) > 0;
161  }
162 
170  public function getArgumentDefinitions() {
171  if (!$this->hasArguments()) {
172  return array();
173  }
174  $commandArgumentDefinitions = array();
176  $annotations = $commandMethodReflection->getTagsValues();
177  $commandParameters = $this->reflectionService->getMethodParameters($this->controllerClassName, $this->controllerCommandName . 'Command');
178  $i = 0;
179  foreach ($commandParameters as $commandParameterName => $commandParameterDefinition) {
180  $explodedAnnotation = preg_split('/\s+/', $annotations['param'][$i], 3);
181  $description = !empty($explodedAnnotation[2]) ? $explodedAnnotation[2] : '';
182  $required = $commandParameterDefinition['optional'] !== TRUE;
183  $commandArgumentDefinitions[] = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\CommandArgumentDefinition', $commandParameterName, $required, $description);
184  $i++;
185  }
186  return $commandArgumentDefinitions;
187  }
188 
196  public function isInternal() {
197  return $this->getCommandMethodReflection()->isTaggedWith('internal');
198  }
199 
207  public function isFlushingCaches() {
208  return $this->getCommandMethodReflection()->isTaggedWith('flushesCaches');
209  }
210 
217  public function getRelatedCommandIdentifiers() {
219  if (!$commandMethodReflection->isTaggedWith('see')) {
220  return array();
221  }
222  $relatedCommandIdentifiers = array();
223  foreach ($commandMethodReflection->getTagValues('see') as $tagValue) {
224  if (preg_match('/^[\\w\\d\\.]+:[\\w\\d]+:[\\w\\d]+$/', $tagValue) === 1) {
225  $relatedCommandIdentifiers[] = $tagValue;
226  }
227  }
228  return $relatedCommandIdentifiers;
229  }
230 
234  protected function getCommandMethodReflection() {
235  if ($this->commandMethodReflection === NULL) {
236  $this->commandMethodReflection = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\MethodReflection', $this->controllerClassName, $this->controllerCommandName . 'Command');
237  }
239  }
240 }
__construct($controllerClassName, $controllerCommandName)
Definition: Command.php:71