diff --git a/src/Symfony/Component/Console/Output/NullOutput.php b/src/Symfony/Component/Console/Output/NullOutput.php
index 557f8afe3c43c..edbadad8a116c 100644
--- a/src/Symfony/Component/Console/Output/NullOutput.php
+++ b/src/Symfony/Component/Console/Output/NullOutput.php
@@ -98,7 +98,7 @@ public function isDebug()
/**
* {@inheritdoc}
*/
- public function writeln($messages, $type = self::OUTPUT_NORMAL)
+ public function writeln($messages, $options = self::OUTPUT_NORMAL)
{
// do nothing
}
@@ -106,7 +106,7 @@ public function writeln($messages, $type = self::OUTPUT_NORMAL)
/**
* {@inheritdoc}
*/
- public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
+ public function write($messages, $newline = false, $options = self::OUTPUT_NORMAL)
{
// do nothing
}
diff --git a/src/Symfony/Component/Console/Output/Output.php b/src/Symfony/Component/Console/Output/Output.php
index cb0e40d2ae90e..b0a334c6a59fb 100644
--- a/src/Symfony/Component/Console/Output/Output.php
+++ b/src/Symfony/Component/Console/Output/Output.php
@@ -121,22 +121,28 @@ public function isDebug()
/**
* {@inheritdoc}
*/
- public function writeln($messages, $type = self::OUTPUT_NORMAL)
+ public function writeln($messages, $options = self::OUTPUT_NORMAL)
{
- $this->write($messages, true, $type);
+ $this->write($messages, true, $options);
}
/**
* {@inheritdoc}
*/
- public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
+ public function write($messages, $newline = false, $options = self::OUTPUT_NORMAL)
{
- if (self::VERBOSITY_QUIET === $this->verbosity) {
+ $messages = (array) $messages;
+
+ $types = self::OUTPUT_NORMAL | self::OUTPUT_RAW | self::OUTPUT_PLAIN;
+ $type = $types & $options ?: self::OUTPUT_NORMAL;
+
+ $verbosities = self::VERBOSITY_QUIET | self::VERBOSITY_NORMAL | self::VERBOSITY_VERBOSE | self::VERBOSITY_VERY_VERBOSE | self::VERBOSITY_DEBUG;
+ $verbosity = $verbosities & $options ?: self::VERBOSITY_NORMAL;
+
+ if ($verbosity > $this->getVerbosity()) {
return;
}
- $messages = (array) $messages;
-
foreach ($messages as $message) {
switch ($type) {
case OutputInterface::OUTPUT_NORMAL:
@@ -147,8 +153,6 @@ public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
case OutputInterface::OUTPUT_PLAIN:
$message = strip_tags($this->formatter->format($message));
break;
- default:
- throw new \InvalidArgumentException(sprintf('Unknown output type given (%s)', $type));
}
$this->doWrite($message, $newline);
diff --git a/src/Symfony/Component/Console/Output/OutputInterface.php b/src/Symfony/Component/Console/Output/OutputInterface.php
index f7f30636feb09..c828c5773cc63 100644
--- a/src/Symfony/Component/Console/Output/OutputInterface.php
+++ b/src/Symfony/Component/Console/Output/OutputInterface.php
@@ -22,40 +22,36 @@
*/
interface OutputInterface
{
- const VERBOSITY_QUIET = 0;
- const VERBOSITY_NORMAL = 1;
- const VERBOSITY_VERBOSE = 2;
- const VERBOSITY_VERY_VERBOSE = 3;
- const VERBOSITY_DEBUG = 4;
+ const VERBOSITY_QUIET = 16;
+ const VERBOSITY_NORMAL = 32;
+ const VERBOSITY_VERBOSE = 64;
+ const VERBOSITY_VERY_VERBOSE = 128;
+ const VERBOSITY_DEBUG = 256;
- const OUTPUT_NORMAL = 0;
- const OUTPUT_RAW = 1;
- const OUTPUT_PLAIN = 2;
+ const OUTPUT_NORMAL = 1;
+ const OUTPUT_RAW = 2;
+ const OUTPUT_PLAIN = 4;
/**
* Writes a message to the output.
*
* @param string|array $messages The message as an array of lines or a single string
* @param bool $newline Whether to add a newline
- * @param int $type The type of output (one of the OUTPUT constants)
- *
- * @throws \InvalidArgumentException When unknown output type is given
+ * @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
*
* @api
*/
- public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL);
+ public function write($messages, $newline = false, $options = 0);
/**
* Writes a message to the output and adds a newline at the end.
*
* @param string|array $messages The message as an array of lines of a single string
- * @param int $type The type of output (one of the OUTPUT constants)
- *
- * @throws \InvalidArgumentException When unknown output type is given
+ * @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
*
* @api
*/
- public function writeln($messages, $type = self::OUTPUT_NORMAL);
+ public function writeln($messages, $options = 0);
/**
* Sets the verbosity of the output.
diff --git a/src/Symfony/Component/Console/Tests/Output/OutputTest.php b/src/Symfony/Component/Console/Tests/Output/OutputTest.php
index cfb4afe15ca63..45e6ddc7dc329 100644
--- a/src/Symfony/Component/Console/Tests/Output/OutputTest.php
+++ b/src/Symfony/Component/Console/Tests/Output/OutputTest.php
@@ -116,16 +116,6 @@ public function testWriteDecoratedMessage()
$this->assertEquals("\033[33;41;5mfoo\033[39;49;25m\n", $output->output, '->writeln() decorates the output');
}
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Unknown output type given (24)
- */
- public function testWriteWithInvalidOutputType()
- {
- $output = new TestOutput();
- $output->writeln('
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: