Skip to content

Instantly share code, notes, and snippets.

@nunomaduro
Created December 16, 2017 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nunomaduro/ba70bb53e2c1900db8b53b1205507842 to your computer and use it in GitHub Desktop.
Save nunomaduro/ba70bb53e2c1900db8b53b1205507842 to your computer and use it in GitHub Desktop.
LaravelConsoleTaskServiceProvider.php
<?php
declare(strict_types=1);
/**
* This file is part of Laravel Console Task.
*
* (c) Nuno Maduro <enunomaduro@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NunoMaduro\LaravelConsoleTask;
use Illuminate\Console\Command;
use Illuminate\Support\ServiceProvider;
/**
* This is an Laravel Console Task Service Provider implementation.
*
* @author Nuno Maduro <enunomaduro@gmail.com>
*/
class LaravelConsoleTaskServiceProvider extends ServiceProvider
{
/**
* {@inheritdoc}
*/
public function boot()
{
/*
* Performs the given task, outputs and
* returns the result.
*
* @param string $title
* @param callable $task
*
* @return bool With the result of the task.
*/
Command::macro(
'task',
function (string $title, callable $task) {
return tap($task(), function ($result) use ($title) {
$this->output->writeln(
"$title: ".($result ? '<info>✔</info>' : '<error>failed</error>')
);
});
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment