PHPackages                             code16/write-to-console - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. code16/write-to-console

AbandonedArchivedLibrary[CLI &amp; Console](/categories/cli)

code16/write-to-console
=======================

Simple Trait to interact with artisan console from any PHP class

v1.1(6y ago)22.3kMITPHPCI failing

Since Jan 3Pushed 6y ago1 watchersCompare

[ Source](https://github.com/code16/write-to-console)[ Packagist](https://packagist.org/packages/code16/write-to-console)[ Docs](https://code16.fr)[ RSS](/packages/code16-write-to-console/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (4)Versions (3)Used By (0)

WriteToConsole trait
====================

[](#writetoconsole-trait)

This is a simple trait to allow a third party class to output to an artisan console.

Useful when implementing heavy procedural scripts which code is shared with other part of the application, or just written in its own class for easier testability.

It simply redirects the `info()` , `error()` , `comment()`, `table()` and `progressBar()` methods to the command object set by calling the public `setConsole()` method of the trait, or just pass-through if no command object is set.

Example
-------

[](#example)

Using the trait in a custom script :

```
namespace App\Tools;

use Code16\WriteToConsole\WriteToConsole;

class DataImporter
{
	use WriteToConsole;

	public function execute()
	{
		$this->info("Import started");

		$progress = $this->progressBar(100);

		for($x=0;$xadvance();
		}

		$this->info("Import finished");
	}

}
```

Calling the script from an artisan console command :

```
