Compare commits

...

2 Commits
0.1.4 ... 0.1.6

Author SHA1 Message Date
Deon George
b0fcdaa375 Added artisan command schedule:list 2018-06-15 14:14:04 +10:00
Deon George
55d369df47 Added helpers.php 2018-06-12 16:09:27 +10:00
3 changed files with 85 additions and 1 deletions

View File

@@ -18,7 +18,10 @@
"autoload": {
"psr-4": {
"Leenooks\\": "src"
}
},
"files": [
"src/helpers.php"
]
},
"extra": {
"laravel": {

View File

@@ -0,0 +1,66 @@
<?php
namespace Leenooks\Commands;
use Illuminate\Console\Command;
use Illuminate\Console\Scheduling\Schedule;
class ScheduleList extends Command
{
protected $signature = 'schedule:list';
protected $description = 'List when scheduled commands are executed.';
/**
* @var Schedule
*/
protected $schedule;
/**
* ScheduleList constructor.
*
* @param Schedule $schedule
*/
public function __construct(Schedule $schedule)
{
parent::__construct();
$this->schedule = $schedule;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$events = array_map(function ($event) {
return [
'cron' => $event->expression,
'command' => static::fixupCommand($event->command),
];
}, $this->schedule->events());
$this->table(
['Cron', 'Command'],
$events
);
}
/**
* If it's an artisan command, strip off the PHP
*
* @param $command
* @return string
*/
protected static function fixupCommand($command)
{
$parts = explode(' ', $command);
if (count($parts) > 2 && $parts[1] === "'artisan'") {
array_shift($parts);
}
return implode(' ', $parts);
}
}

15
src/helpers.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
// is_json helper
if (! function_exists('is_json')) {
function is_json($string) {
try {
json_decode($string);
} catch (\Exception $e) {
return FALSE;
}
return (json_last_error() == JSON_ERROR_NONE);
}
}