Skip to content

Commit

Permalink
Merge pull request #19 from mcampbell508/remove-command-strings-via-c…
Browse files Browse the repository at this point in the history
…onfig

Remove command strings via config
  • Loading branch information
hmazter authored May 21, 2018
2 parents 0f9f153 + e894471 commit 0cfdc96
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
return [
'remove_strings_from_command' => [
"'".PHP_BINARY."'",
"'artisan'",
],
];
```

## Known limitations

Laravel ships with some special scheduling functions ex `between`, `unlessBetween`, `when` and `skip`
Expand Down
8 changes: 8 additions & 0 deletions config/schedule-list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'remove_strings_from_command' => [
"'".PHP_BINARY."'",
"'artisan'",
],
];
8 changes: 7 additions & 1 deletion src/ScheduleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions src/ScheduleListServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,22 @@ 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.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/schedule-list.php', 'schedule-list');

$this->commands([
Console\ListScheduler::class
]);
Expand Down
20 changes: 20 additions & 0 deletions tests/Function/ScheduleEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 0cfdc96

Please sign in to comment.