* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org/wiki/indexing:oai-pmh Wiki */ namespace VuFindHarvest\ConsoleOutput; /** * Trait for shared output functionality. * * @category VuFind * @package Harvest_Tools * @author Demian Katz * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org/wiki/indexing:oai-pmh Wiki */ trait WriterAwareTrait { /** * Writer helper * * @var WriterInterface */ protected $outputWriter = null; /** * Set an object to accept console output messages. * * @param WriterInterface $writer Writer object * * @return void */ public function setOutputWriter(WriterInterface $writer) { $this->outputWriter = $writer; } /** * Write a string to the console output writer (if set). * * @param string $str String to write. * * @return void */ protected function write($str) { // Bypass output when silent: if ($this->outputWriter) { $this->outputWriter->write($str); } } /** * Write a string w/newline to the console output writer (if set). * * @param string $str String to write. * * @return void */ protected function writeLine($str) { // Bypass output when silent: if ($this->outputWriter) { $this->outputWriter->writeLine($str); } } }