Neos\Kickstarter\Service\GeneratorService::generateCommandController PHP Method

generateCommandController() public method

Generate a command controller with the given name for the given package
public generateCommandController ( string $packageKey, string $controllerName, boolean $overwrite = false ) : array
$packageKey string The package key of the controller's package
$controllerName string The name of the new controller
$overwrite boolean Overwrite any existing files?
return array An array of generated filenames
    public function generateCommandController($packageKey, $controllerName, $overwrite = false)
    {
        list($baseNamespace, $namespaceEntryPath) = $this->getPrimaryNamespaceAndEntryPath($this->packageManager->getPackage($packageKey));
        $controllerName = ucfirst($controllerName) . 'Command';
        $controllerClassName = $controllerName . 'Controller';
        $templatePathAndFilename = 'resource://Neos.Kickstarter/Private/Generator/Controller/CommandControllerTemplate.php.tmpl';
        $contextVariables = array();
        $contextVariables['packageKey'] = $packageKey;
        $contextVariables['packageNamespace'] = trim($baseNamespace, '\\');
        $contextVariables['controllerClassName'] = $controllerClassName;
        $contextVariables['controllerName'] = $controllerName;
        $fileContent = $this->renderTemplate($templatePathAndFilename, $contextVariables);
        $controllerFilename = $controllerClassName . '.php';
        $controllerPath = Files::concatenatePaths([$namespaceEntryPath, 'Command']) . '/';
        $targetPathAndFilename = $controllerPath . $controllerFilename;
        $this->generateFile($targetPathAndFilename, $fileContent, $overwrite);
        return $this->generatedFiles;
    }

Usage Example

 /**
  * Kickstart a new command controller
  *
  * Creates a new command controller with the given name in the specified
  * package. The generated controller class already contains an example command.
  *
  * @param string $packageKey The package key of the package for the new controller
  * @param string $controllerName The name for the new controller. This may also be a comma separated list of controller names.
  * @param boolean $force Overwrite any existing controller.
  * @return string
  * @see neos.kickstarter:kickstart:actioncontroller
  */
 public function commandControllerCommand($packageKey, $controllerName, $force = false)
 {
     $this->validatePackageKey($packageKey);
     if (!$this->packageManager->isPackageAvailable($packageKey)) {
         $this->outputLine('Package "%s" is not available.', array($packageKey));
         exit(2);
     }
     $generatedFiles = array();
     $controllerNames = Arrays::trimExplode(',', $controllerName);
     foreach ($controllerNames as $currentControllerName) {
         $generatedFiles += $this->generatorService->generateCommandController($packageKey, $currentControllerName, $force);
     }
     $this->outputLine(implode(PHP_EOL, $generatedFiles));
 }