/
ConsoleServiceProvider.php
89 lines (79 loc) · 3.19 KB
/
ConsoleServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Console;
use Flarum\Console\Cache\Factory;
use Flarum\Database\Console\MigrateCommand;
use Flarum\Database\Console\ResetCommand;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Console\AssetsPublishCommand;
use Flarum\Foundation\Console\CacheClearCommand;
use Flarum\Foundation\Console\InfoCommand;
use Illuminate\Console\Scheduling\CacheEventMutex;
use Illuminate\Console\Scheduling\CacheSchedulingMutex;
use Illuminate\Console\Scheduling\EventMutex;
use Illuminate\Console\Scheduling\Schedule as LaravelSchedule;
use Illuminate\Console\Scheduling\ScheduleListCommand;
use Illuminate\Console\Scheduling\ScheduleRunCommand;
use Illuminate\Console\Scheduling\SchedulingMutex;
use Illuminate\Contracts\Container\Container;
class ConsoleServiceProvider extends AbstractServiceProvider
{
/**
* {@inheritdoc}
*/
public function register()
{
// Used by Laravel to proxy artisan commands to its binary.
// Flarum uses a similar binary, but it's called flarum.
if (! defined('ARTISAN_BINARY')) {
define('ARTISAN_BINARY', 'flarum');
}
// Flarum doesn't fully use Laravel's cache system, but rather
// creates and binds a single cache store.
// See \Flarum\Foundation\InstalledSite::registerCache
// Since certain config options (e.g. withoutOverlapping, onOneServer)
// need the cache, we must override the cache factory we give to the scheduling
// mutexes so it returns our single custom cache.
$this->container->bind(EventMutex::class, function ($container) {
return new CacheEventMutex($container->make(Factory::class));
});
$this->container->bind(SchedulingMutex::class, function ($container) {
return new CacheSchedulingMutex($container->make(Factory::class));
});
$this->container->singleton(LaravelSchedule::class, function (Container $container) {
return $container->make(Schedule::class);
});
$this->container->singleton('flarum.console.commands', function () {
return [
AssetsPublishCommand::class,
CacheClearCommand::class,
InfoCommand::class,
MigrateCommand::class,
ResetCommand::class,
ScheduleListCommand::class,
ScheduleRunCommand::class
// Used internally to create DB dumps before major releases.
// \Flarum\Database\Console\GenerateDumpCommand::class
];
});
$this->container->singleton('flarum.console.scheduled', function () {
return [];
});
}
/**
* {@inheritDoc}
*/
public function boot(Container $container)
{
$schedule = $container->make(LaravelSchedule::class);
foreach ($container->make('flarum.console.scheduled') as $scheduled) {
$event = $schedule->command($scheduled['command'], $scheduled['args']);
$scheduled['callback']($event);
}
}
}