. */ namespace Doctrine\ORM\Tools\Cli; abstract class AbstractPrinter { protected $_stream; protected $_maxColumnSize; protected $_styles; public function __construct($stream = STDOUT) { $this->_stream = $stream; $this->_maxColumnSize = 80; $this->_initStyles(); } protected function _initStyles() { // Defines base styles $this->addStyles(array( 'ERROR' => new Style(), 'INFO' => new Style(), 'COMMENT' => new Style(), 'HEADER' => new Style(), 'NONE' => new Style(), )); } public function addStyles($styles) { foreach ($styles as $name => $style) { $this->addStyle($name, $style); } } public function addStyle($name, Style $style) { $this->_styles[strtoupper($name)] = $style; } public function getStyle($name) { $name = strtoupper($name); return isset($this->_styles[$name]) ? $this->_styles[$name] : null; } /** * Sets the maximum column size (defines the CLI margin). * * @param integer $maxColumnSize The maximum column size for a message */ public function setMaxColumnSize($maxColumnSize) { $this->_maxColumnSize = $maxColumnSize; } /** * Writes to output stream the message, formatting it by applying the defined style. * * @param string $message Message to be outputted * @param mixed $style Optional style to be applied in message */ public function write($message, $style = 'ERROR') { $style = is_string($style) ? $this->getStyle($style) : $style; fwrite($this->_stream, $this->format($message, $style)); } /** * Formats the given message with the defined style. * * @param string $message Message to be formatted * @param mixed $style Style to be applied in message * @return string Formatted message */ abstract public function format($message, Style $style); }