Skip to content

Instantly share code, notes, and snippets.

@pankajlele
Created July 29, 2017 11:02
Show Gist options
  • Save pankajlele/4fe3aa7cb76bff15ce2881ed6df0fe22 to your computer and use it in GitHub Desktop.
Save pankajlele/4fe3aa7cb76bff15ce2881ed6df0fe22 to your computer and use it in GitHub Desktop.
This trait can be used to write console output from service classes.
<?php
namespace Yout\Package\Command;
/*
* This script belongs to the Flow package "Your.Package".
*/
use TYPO3\Flow\Cli\ConsoleOutput;
/**
* A trait to add ConsoleOutput functionality to other service classes
*/
trait ConsoleOutputTrait
{
/**
* @var ConsoleOutput
*/
protected $consoleOutput = null;
/**
* Console output
*
* @param ConsoleOutput $consoleOutput
*/
public function setConsoleOutput(ConsoleOutput $consoleOutput)
{
$this->consoleOutput = $consoleOutput;
}
/**
* Writes line to console output
*
* This function does nothing in Web context
*
* @param $text
* @param array $arguments
*/
protected function consoleOutputLine($text, $arguments = [])
{
if ($this->consoleOutput !== null && FLOW_SAPITYPE === 'CLI') {
$this->consoleOutput->outputLine($text, $arguments);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment