2022-06-24 18:17:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace LDC\WebAdminSecureLaravel;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Console\Scheduling\Schedule;
|
2023-06-02 16:51:52 +02:00
|
|
|
use Illuminate\Contracts\Foundation\Application;
|
2022-06-24 18:17:20 +02:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
use Illuminate\Routing\Router;
|
|
|
|
|
use LDC\WebAdminSecureLaravel\Console\SyncFromLDCWeb;
|
|
|
|
|
use LDC\WebAdminSecureLaravel\Http\Middleware\AdminSecureMiddleware;
|
|
|
|
|
|
|
|
|
|
class AdminSecureServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Bootstrap any application services.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function boot()
|
|
|
|
|
{
|
|
|
|
|
$this->publishes([
|
|
|
|
|
__DIR__ . '/../config' => config_path(),
|
|
|
|
|
], 'config');
|
|
|
|
|
|
2023-06-02 16:51:52 +02:00
|
|
|
// * Register the command if we are using the application via the CLI .
|
|
|
|
|
$this->commands([SyncFromLDCWeb::class]);
|
|
|
|
|
|
|
|
|
|
// * Set filter condition
|
|
|
|
|
$this->app->singleton('hasToFilterIp', fn (Application $app) => $app->environment('production'));
|
2022-06-24 18:17:20 +02:00
|
|
|
|
|
|
|
|
// * Cron Report everyday
|
|
|
|
|
$this->app->booted(function () {
|
2023-06-02 16:51:52 +02:00
|
|
|
if ($this->app->make('hasToFilterIp')) {
|
2022-07-04 11:41:39 +02:00
|
|
|
/** @var \Illuminate\Console\Scheduling\Schedule */
|
|
|
|
|
$schedule = $this->app->make(Schedule::class);
|
|
|
|
|
$schedule->command('ldcweb:admin-secure-sync')->daily();
|
|
|
|
|
}
|
2022-06-24 18:17:20 +02:00
|
|
|
});
|
|
|
|
|
|
2023-06-02 16:51:52 +02:00
|
|
|
/** @var \Illuminate\Routing\Router */
|
2022-06-24 18:17:20 +02:00
|
|
|
$router = $this->app->make(Router::class);
|
|
|
|
|
$router->aliasMiddleware('admin-secure', AdminSecureMiddleware::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Register any application services.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function register()
|
|
|
|
|
{
|
|
|
|
|
$this->mergeConfigFrom(
|
|
|
|
|
sprintf('%s/../config/admin-secure.php', __DIR__),
|
|
|
|
|
'admin-secure'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|