PHP code example of code16 / write-to-console

1. Go to this page and download the library: Download code16/write-to-console library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

code16 / write-to-console example snippets



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;$x<100;$x++) {
			$progress->advance();
		}

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

}






namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Tools\DataImporter;

class DataImportsCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'data:import';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Import DATA';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {   
        $importer = app(DataImporter::class);
        $importer->setConsole($this);
        
        $importer->execute();

    }
}


    public function handle()
    {   
        $importer = app(DataImporter::class);
        $importer->setConsole($this);

        $logger = app(\Psr\Log\LoggerInterface::class);
        $importer->setLogger($logger);

        $importer->execute();

    }