# Writer

A Writer writes strings to some context. WriterInterface describe the interface for a component in charge of writing.

# Writers Container

WritersInterface describes a service container providing access to out, error, debug and log writers.

🧔🏾 Writers are intended to be used for providing multi-channel output

use Chevere\Components\Writer\Writers;

$writers = new Writers;

🧞 By default, it populates out to php://stdout (w) and error to php://stderr (w)

Methods withOut, withError, withDebug and withLog can be used to specify each writer.

In the example below, the withDebug method is used to pass a stream writer for /var/debug_output file.

use Chevere\Components\Writer\StreamWriterFromString;

$writers = $writers
        new StreamWriterFromString('/var/debug_output', 'w')

# Concrete Writers

# StreamWriter

The Chevere\Components\Writer\StreamWriter is a writer that writes to a stream.

Code below shows how to initiate a StreamWriter.

use Chevere\Components\Writer\StreamWriter;
use Laminas\Diactoros\StreamFactory;

$stream = (new StreamFactory)->createStream('');
$writer = new StreamWriter($stream);
$writer->write('write some');

A StreamWriter can be also created with StreamWriterFromString.

use Chevere\Components\Writer\StreamWriterFromString;

$writer = new StreamWriterFromString('');
$writer->write('something else');