Created
January 21, 2014 08:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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