Skip to content

Instantly share code, notes, and snippets.

@bwaidelich
Created January 21, 2014 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwaidelich/8536527 to your computer and use it in GitHub Desktop.
Save bwaidelich/8536527 to your computer and use it in GitHub Desktop.
An AbstractCommandController that adds a flag "force" to the output* method in order to render strings directly to the console
<?php
namespace Your\Package\Command;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Cli\CommandController;
/**
* Abstract base class for command controllers of the "Your.Package" package
*/
abstract class AbstractCommandController extends CommandController {
/**
* Outputs specified text to the console window
* @see CommandController::output()
*
* @param string $text Text to output
* @param array $arguments Optional arguments to use for sprintf
* @param boolean $force If TRUE, the string will be outputted directly
* @return void
*/
protected function output($text, array $arguments = array(), $force = FALSE) {
if ($arguments !== array()) {
$text = vsprintf($text, $arguments);
}
if ($force) {
echo $text;
} else {
$this->response->appendContent($text);
}
}
/**
* Outputs specified text to the console window and appends a line break
* @see CommandController::outputLine()
*
* @param string $text Text to output
* @param array $arguments Optional arguments to use for sprintf
* @param boolean $force If TRUE, the string will be outputted directly
* @return void
* @see output()
* @see outputLines()
*/
protected function outputLine($text = '', array $arguments = array(), $force = FALSE) {
$this->output($text . PHP_EOL, $arguments, $force);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment