| 1 | <?php |
||
| 9 | class ConsoleInterface extends AbstractLogger |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var ConsoleLogger |
||
| 13 | */ |
||
| 14 | private $logger; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var OutputInterface |
||
| 18 | */ |
||
| 19 | private $output; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * ConsoleInterface constructor. |
||
| 23 | * |
||
| 24 | * @param ConsoleInterface|OutputInterface|null $output |
||
| 25 | */ |
||
| 26 | 18 | public function __construct ($output = null) |
|
| 27 | { |
||
| 28 | 18 | $this->logger = null; |
|
| 29 | |||
| 30 | 18 | if (!is_null($output)) |
|
| 31 | 18 | { |
|
| 32 | 18 | $this->output = ($output instanceof ConsoleInterface) ? $output->getOutputInterface() : $output; |
|
| 33 | 18 | $this->logger = new ConsoleLogger($this->output); |
|
| 34 | 18 | } |
|
| 35 | 18 | } |
|
| 36 | |||
| 37 | /** |
||
| 38 | * Return the OutputInterface object |
||
| 39 | * |
||
| 40 | * @return OutputInterface |
||
| 41 | */ |
||
| 42 | public function getOutputInterface () |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Logs with an arbitrary level. |
||
| 49 | * |
||
| 50 | * @param mixed $level |
||
| 51 | * @param string $message |
||
| 52 | * @param array $context |
||
| 53 | * |
||
| 54 | * @return null |
||
| 55 | */ |
||
| 56 | 3 | public function log ($level, $message, array $context = array()) |
|
| 57 | { |
||
| 58 | 3 | if (!is_null($this->output)) |
|
| 59 | 3 | { |
|
| 60 | 3 | $this->logger->log($level, $message, $context); |
|
| 61 | 3 | } |
|
| 62 | 3 | } |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Writes a message to the output and adds a newline at the end. |
||
| 66 | * |
||
| 67 | * @param string|array $messages The message as an array of lines of a single string |
||
| 68 | * @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL |
||
| 69 | */ |
||
| 70 | public function writeln ($messages, $options = 0) |
||
| 74 | } |