1 <?php
2 /**
3 * Part of the Joomla Framework Application Package
4 *
5 * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
6 * @license GNU General Public License version 2 or later; see LICENSE
7 */
8
9 namespace Joomla\Application\Cli;
10
11 use Joomla\Application\Cli\Output\Processor\ProcessorInterface;
12
13 /**
14 * Class CliOutput
15 *
16 * @since 1.0
17 */
18 abstract class CliOutput
19 {
20 /**
21 * Color processing object
22 *
23 * @var ProcessorInterface
24 * @since 1.0
25 */
26 protected $processor;
27
28 /**
29 * Constructor
30 *
31 * @param ProcessorInterface $processor The output processor.
32 *
33 * @since 1.1.2
34 */
35 public function __construct(ProcessorInterface $processor = null)
36 {
37 $this->setProcessor(($processor instanceof ProcessorInterface) ? $processor : new Output\Processor\ColorProcessor);
38 }
39
40 /**
41 * Set a processor
42 *
43 * @param ProcessorInterface $processor The output processor.
44 *
45 * @return Stdout Instance of $this to allow chaining.
46 *
47 * @since 1.0
48 */
49 public function setProcessor(ProcessorInterface $processor)
50 {
51 $this->processor = $processor;
52
53 return $this;
54 }
55
56 /**
57 * Get a processor
58 *
59 * @return ProcessorInterface
60 *
61 * @since 1.0
62 * @throws \RuntimeException
63 */
64 public function getProcessor()
65 {
66 if ($this->processor)
67 {
68 return $this->processor;
69 }
70
71 throw new \RuntimeException('A ProcessorInterface object has not been set.');
72 }
73
74 /**
75 * Write a string to an output handler.
76 *
77 * @param string $text The text to display.
78 * @param boolean $nl True (default) to append a new line at the end of the output string.
79 *
80 * @return void
81 *
82 * @since 1.0
83 * @codeCoverageIgnore
84 */
85 abstract public function out($text = '', $nl = true);
86 }
87