diff --git a/README.md b/README.md index 0abbd6f..5d840a8 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,26 @@ For occasions when you need to access the list of scheduled events programmatica Inject the `ScheduleList` or resolve it from the Container and then call `all()` to get all scheduled events. Usage of it can be seen in [ListScheduler::handle](src/Console/ListScheduler.php) +## Define PHP Binary Path + +If you use custom PHP Binary paths or you are using `\Hmazter\LaravelScheduleList\ScheduleList::all` within the context of a web application and not through the console, you can publish the package config file and defining your own binary path: + +``` +php artisan vendor:publish --provider="Hmazter\LaravelScheduleList\ScheduleListServiceProvider" --tag="config" +``` + +For example `config/schedule-list.php`: +``` + [ + "'".PHP_BINARY."'", + "'artisan'", + ], +]; +``` + ## Known limitations Laravel ships with some special scheduling functions ex `between`, `unlessBetween`, `when` and `skip` diff --git a/config/schedule-list.php b/config/schedule-list.php new file mode 100644 index 0000000..b18653c --- /dev/null +++ b/config/schedule-list.php @@ -0,0 +1,8 @@ + [ + "'".PHP_BINARY."'", + "'artisan'", + ], +]; diff --git a/src/ScheduleEvent.php b/src/ScheduleEvent.php index 4e15ebb..cfefc3c 100644 --- a/src/ScheduleEvent.php +++ b/src/ScheduleEvent.php @@ -97,7 +97,13 @@ public function getShortCommand(): string { $command = $this->getFullCommand(); $command = substr($command, 0, strpos($command, '>')); - $command = trim(str_replace(["'".PHP_BINARY."'", "'artisan'"], '', $command)); + $command = trim(str_replace( + config('schedule-list.remove_strings_from_command', [ + "'".PHP_BINARY."'", + "'artisan'", + ]), '', $command) + ); + return $command; } diff --git a/src/ScheduleListServiceProvider.php b/src/ScheduleListServiceProvider.php index 1255fb3..2e9076f 100644 --- a/src/ScheduleListServiceProvider.php +++ b/src/ScheduleListServiceProvider.php @@ -22,6 +22,13 @@ class ScheduleListServiceProvider extends ServiceProvider */ protected $defer = false; + public function boot() + { + $this->publishes([ + __DIR__ . '/../config/schedule-list.php' => config_path('schedule-list.php'), + ], 'config'); + } + /** * Register the service provider. * @@ -29,6 +36,8 @@ class ScheduleListServiceProvider extends ServiceProvider */ public function register() { + $this->mergeConfigFrom(__DIR__.'/../config/schedule-list.php', 'schedule-list'); + $this->commands([ Console\ListScheduler::class ]); diff --git a/tests/Function/ScheduleEventTest.php b/tests/Function/ScheduleEventTest.php index 9f91ca9..66988e7 100644 --- a/tests/Function/ScheduleEventTest.php +++ b/tests/Function/ScheduleEventTest.php @@ -75,4 +75,24 @@ public function scheduleEvent_with6PositionCronExpression_truncatesCronExpressio self::assertEquals('* * * * *', $scheduleEvent->getExpression()); self::assertInstanceOf(Carbon::class, $scheduleEvent->getNextRunDate()); } + + /** @test */ + public function getShortCommand_removesStringsProvidedThroughConfig() + { + config(['schedule-list.remove_strings_from_command' => [ + "'/usr/bin/php'", + "'art'", + ]]); + + $command = "'/usr/bin/php' 'art' test:hello --name=\"John Doe\" > /dev/null"; + + $scheduleEvent = new ScheduleEvent( + '', + null, + $command, + '' + ); + + self::assertEquals('test:hello --name="John Doe"', $scheduleEvent->getShortCommand()); + } } \ No newline at end of file