-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsTaskServiceProvider.php
More file actions
172 lines (151 loc) · 4.89 KB
/
sTaskServiceProvider.php
File metadata and controls
172 lines (151 loc) · 4.89 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php namespace Seiger\sTask;
use EvolutionCMS\ServiceProvider;
use Illuminate\Console\Scheduling\Schedule;
use Seiger\sTask\Console\PublishAssets;
use Seiger\sTask\Console\TaskWorker;
/**
* Class sTaskServiceProvider
*
* Service provider for sTask package. Handles registration,
* publishing resources, and managing task functionality.
*
* @package Seiger\sTask
* @author Seiger IT Team
* @since 1.0.0
*/
class sTaskServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
// Merge configuration first
$this->mergeConfigFrom(dirname(__DIR__) . '/config/sTaskCheck.php', 'cms.settings');
// Register singletons
$this->app->singleton(sTask::class);
$this->app->alias(sTask::class, 'sTask');
// Create storage directory for logs
$this->ensureStorageExists();
// Load migrations, translations, views
$this->loadMigrationsFrom(__DIR__ . '/Database/Migrations');
$this->loadTranslationsFrom(dirname(__DIR__) . '/lang', 'sTask');
$this->loadViewsFrom(dirname(__DIR__) . '/views', 'sTask');
// Load routes
$this->loadRoutes();
// Publish resources
$this->publishResources();
// Setup console schedule for commands
$this->app->booted(function () {
$this->defineConsoleSchedule();
});
}
/**
* Ensure storage directory exists
*/
protected function ensureStorageExists(): void
{
$logPath = storage_path('stask');
if (!file_exists($logPath)) {
mkdir($logPath, 0755, true);
}
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
// Register services
$this->registerServices();
// Load plugins
$this->loadPluginsFrom(dirname(__DIR__) . '/plugins/');
// Register console commands
if ($this->app->runningInConsole()) {
$this->commands([
TaskWorker::class,
PublishAssets::class,
]);
}
}
/**
* Register sTask services
*
* @return void
*/
protected function registerServices(): void
{
// Register WorkerService as singleton for performance
$this->app->singleton(\Seiger\sTask\Services\WorkerService::class);
// Register MetricsService as singleton
$this->app->singleton(\Seiger\sTask\Services\MetricsService::class);
// Register sTask as singleton
$this->app->singleton(\Seiger\sTask\sTask::class);
}
/**
* Load custom routes
*
* @return void
*/
protected function loadRoutes()
{
$this->app->router->middlewareGroup('mgr', config('app.middleware.mgr', []));
include(__DIR__ . '/Http/routes.php');
}
/**
* Publish the necessary resources for the package.
*
* @return void
*/
protected function publishResources()
{
$this->publishes([
dirname(__DIR__) . '/config/sTaskAlias.php' => config_path('app/aliases/sTask.php', true),
dirname(__DIR__) . '/images/seigerit.svg' => public_path('assets/site/seigerit.svg'),
dirname(__DIR__) . '/images/logo.svg' => public_path('assets/site/stask.svg'),
dirname(__DIR__) . '/css/tailwind.min.css' => public_path('assets/site/stask.min.css'),
dirname(__DIR__) . '/js/main.js' => public_path('assets/site/stask.js'),
dirname(__DIR__) . '/js/tooltip.js' => public_path('assets/site/seigerit.tooltip.js'),
], 'stask');
}
/**
* Define the application's command schedule.
*
* Sets up the Laravel scheduler singleton with timezone support.
* This enables scheduled execution of console commands.
*
* @note Check available timezones using timezone_identifiers_list()
* @return void
*/
protected function defineConsoleSchedule()
{
$this->app->singleton(Schedule::class, function ($app) {
return tap(new Schedule(now()->timezoneName), function ($schedule) {
$this->schedule($schedule->useCache('file'));
});
});
}
/**
* Define the application's command schedule.
*
* Iterates through all registered commands and calls their schedule
* method to define when each command should be executed.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
public function schedule(Schedule $schedule)
{
// Schedule commands if they have a schedule method
$commands = [TaskWorker::class];
foreach ($commands as $command) {
$instance = new $command;
if (method_exists($instance, 'schedule')) {
$instance->schedule($schedule);
}
}
}
}