/** * @param string $extensionKey * @param string $p1 * @param string $p2 * @param string $p3 * @param string $p4 * @param string $p5 * @return string * @return void */ public function indexAction($extensionKey = NULL, $p1 = NULL, $p2 = NULL, $p3 = NULL, $p4 = NULL, $p5 = NULL) { if (!$extensionKey && !$p1 && !$p2 && !$p3 && !$p4 && !$p5) { list($extensionKey, $p1, $p2, $p3, $p4, $p5) = array_pad((array) $this->getBackendUserAuthentication()->getModuleData('tools_schema_arguments'), 6, NULL); } else { $this->getBackendUserAuthentication()->pushModuleData('tools_schema_arguments', array($extensionKey, $p1, $p2, $p3, $p4, $p5)); } if (NULL === $extensionKey) { $extensionKey = 'TYPO3.Fluid'; } list($vendor, $legacyExtensionKey) = $this->schemaService->getRealExtensionKeyAndVendorFromCombinedExtensionKey($extensionKey); $version = ExtensionManagementUtility::getExtensionVersion($extensionKey); $namespaceName = str_replace('_', '', $legacyExtensionKey); $namespaceName = strtolower($namespaceName); $namespaceAlias = str_replace('_', '', $extensionKey); if (isset($this->extensionKeyToNamespaceMap[$legacyExtensionKey])) { $namespaceAlias = $this->extensionKeyToNamespaceMap[$legacyExtensionKey]; } $segments = array($p1, $p2, $p3, $p4, $p5); $segments = $this->trimPathSegments($segments); $arguments = $this->segmentsToArguments($extensionKey, $segments); $extensionName = GeneralUtility::underscoredToUpperCamelCase($legacyExtensionKey); $extensionKeys = $this->detectExtensionsContainingViewHelpers(); $displayHeadsUp = FALSE; if (isset($this->extensionKeyToNamespaceMap[$namespaceName])) { $namespaceName = $this->extensionKeyToNamespaceMap[$namespaceName]; } $tree = $this->buildTreeFromClassPath(ExtensionManagementUtility::extPath($legacyExtensionKey, 'Classes/ViewHelpers/')); $viewHelperArguments = array(); $node = NULL; $docComment = ''; $className = implode('/', $segments); if (TRUE === ExtensionManagementUtility::isLoaded($legacyExtensionKey)) { $extensionPath = ExtensionManagementUtility::extPath($legacyExtensionKey); if (!empty($className)) { $className = $vendor . '\\' . $extensionName . '\\ViewHelpers\\' . str_replace('/', '\\', $className); $viewHelperArguments = $this->objectManager->get($className)->prepareArguments(); $reflection = new ClassReflection($className); $docComment = $reflection->getDocComment(); $this->docCommentParser->parseDocComment($docComment); $docComment = $this->docCommentParser->getDescription(); $docComment = trim($docComment, "/ \n"); } else { $readmeFile = $extensionPath . 'Classes/ViewHelpers/README.md'; if (TRUE === file_exists($readmeFile)) { $readmeFile = file_get_contents($readmeFile); } else { unset($readmeFile); } } } $variables = array('view' => 'Index', 'action' => 'index', 'readmeFile' => $readmeFile, 'history' => $history, 'name' => end($segments), 'schemaFile' => $relativeSchemaFile, 'keys' => array(), 'namespaceUrl' => $targetNamespaceUrl, 'displayHeadsUp' => $displayHeadsUp, 'namespaceName' => $namespaceName, 'namespaceAlias' => $namespaceAlias, 'className' => $className, 'ns' => $namespaceName, 'isFile' => class_exists($className), 'arguments' => $arguments, 'segments' => $segments, 'markdownBlacklisted' => in_array($extensionKey, $this->markdownBlacklistedExtensionKeys), 'viewHelperArguments' => $viewHelperArguments, 'docComment' => $docComment, 'tree' => $tree, 'version' => $version, 'extensionKey' => $extensionKey, 'extensionKeys' => $extensionKeys, 'extensionName' => $extensionName); $this->view->assignMultiple($variables); }
/** * Generate the XML Schema for a given class name. * * @param string $className Class name to generate the schema for. * @param \SimpleXMLElement $xmlRootNode XML root node where the xsd:element is appended. * @return void */ protected function generateXmlForClassName($className, \SimpleXMLElement $xmlRootNode) { $reflectionClass = new ClassReflection($className); if (!$reflectionClass->isSubclassOf($this->abstractViewHelperReflectionClass)) { return; } $tagName = $this->getTagNameForClass($className); $xsdElement = $xmlRootNode->addChild('xsd:element'); $xsdElement['name'] = $tagName; $this->docCommentParser->parseDocComment($reflectionClass->getDocComment()); $this->addDocumentation($this->docCommentParser->getDescription(), $xsdElement); $xsdComplexType = $xsdElement->addChild('xsd:complexType'); $xsdComplexType['mixed'] = 'true'; $xsdSequence = $xsdComplexType->addChild('xsd:sequence'); $xsdAny = $xsdSequence->addChild('xsd:any'); $xsdAny['minOccurs'] = '0'; $xsdAny['maxOccurs'] = '1'; $this->addAttributes($className, $xsdComplexType); }
/** * @param Request $request * @return Response */ public function processRequest(Request $request) { list($controllerClassName, $actionName) = explode('->', $request->getTask()); /** @var ControllerInterface $controller */ $controller = GeneralUtility::makeInstance(ObjectManager::class)->get($controllerClassName); $methodName = $actionName . 'Command'; $response = new Response(); $response->getReport()->setTitle('Enter command arguments')->setContent('Fill in the arguments to execute'); $expectedCommandArguments = $this->getExpectedArgumentsForMethod($controller, $methodName); $commandArguments = $this->buildArgumentArray($controller, $methodName, $request->getArguments()); foreach ($expectedCommandArguments as $expectedCommandArgument) { $expectedCommandArgumentName = $expectedCommandArgument->getName(); list($expectedArgumentType, $expectedArgumentDescription) = $this->parseDocCommentOfArgument($expectedCommandArgument, $expectedCommandArgumentName); $fieldType = $this->getFieldForArgumentNameAndType($expectedCommandArgumentName, $expectedArgumentType); /** @var FieldInterface $field */ $field = new $fieldType(); $field->setName($expectedCommandArgumentName); if ($expectedArgumentDescription) { $field->setLabel($expectedArgumentDescription); } else { $field->setLabel('Argument: ' . $expectedCommandArgumentName); } $response->getSheet()->addField($field); } if (count($expectedCommandArguments) > count($request->getArguments())) { // We lack some arguments - return the response now so the client can fill those values. // Present a small report outputting the doc comment $methodReflection = new \ReflectionMethod($controller, $methodName); $docCommentParser = new DocCommentParser(); $docCommentParser->parseDocComment($methodReflection->getDocComment()); $response->setReport(new SuccessReport($this->getTaskConfiguration()->getDescription(), $docCommentParser->getDescription())); return $response; } try { $temporaryResponse = new \TYPO3\CMS\Extbase\Mvc\Cli\Response(); $responseProperty = new \ReflectionProperty($controller, 'response'); $responseProperty->setAccessible(TRUE); $responseProperty->setValue($controller, $temporaryResponse); // Catch output of any manual calls to outputLine() or Response->send() from controller action ob_start(); call_user_func_array([$controller, $methodName], array_values($commandArguments)); $output = ob_get_clean(); // Append any finish output accumulated in Response; this normally gets output after finishing a Request // but we bypass the Request and call the command methods directly - so we need to fetch this output. $output .= $temporaryResponse->getContent(); $response->setPayload($output); $response->setReport(new SuccessReport(sprintf('CommandController executed (exit code: %d)', $temporaryResponse->getExitCode()), empty($output) ? 'There was no output from the command' : 'Output is attached as response payload'))->complete(); } catch (\Exception $error) { $response->setReport(new ErrorReport(sprintf('CommandController error (%d)', $error->getCode()), $error->getMessage())); } return $response; }