Skip to content

Commit

Permalink
[11.x] Adds withSchedule to bootstrap/app.php file (#50755)
Browse files Browse the repository at this point in the history
* Adds `withSchedule`

* formatting

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
nunomaduro and taylorotwell committed Mar 25, 2024
1 parent bf02fde commit 7c0e6ad
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Illuminate/Foundation/Configuration/ApplicationBuilder.php
Expand Up @@ -3,6 +3,8 @@
namespace Illuminate\Foundation\Configuration;

use Closure;
use Illuminate\Console\Application as Artisan;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Contracts\Console\Kernel as ConsoleKernel;
use Illuminate\Contracts\Http\Kernel as HttpKernel;
use Illuminate\Foundation\Application;
Expand Down Expand Up @@ -280,6 +282,21 @@ protected function withCommandRouting(array $paths)
});
}

/**
* Register the scheduled tasks for the application.
*
* @param callable(Schedule $schedule): void $callback
* @return $this
*/
public function withSchedule(callable $callback)
{
$this->app->afterResolving(ConsoleKernel::class, function (ConsoleKernel $kernel) use ($callback) {
Artisan::starting(fn () => $callback($this->app->make(Schedule::class)));
});

return $this;
}

/**
* Register and configure the application's exception handler.
*
Expand Down

0 comments on commit 7c0e6ad

Please sign in to comment.