84 lines
2.0 KiB
PHP
84 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Notifications\ChannelManager;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Blade;
|
|
use Illuminate\Support\Facades\Event;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Support\Facades\Notification;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
use App\Events\Echomail as EchomailEvent;
|
|
use App\Events\Matrix\Message;
|
|
use App\Listeners\EchomailListener;
|
|
use App\Listeners\Matrix\MessageListener;
|
|
use App\Notifications\Channels\{EchomailChannel,MatrixChannel,NetmailChannel};
|
|
use App\Models\{Echomail,Netmail,User};
|
|
use App\Traits\SingleOrFail;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
use SingleOrFail;
|
|
|
|
/**
|
|
* Register any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
Notification::resolved(function (ChannelManager $service) {
|
|
$service->extend('echomail', function ($app) {
|
|
return new EchomailChannel($app->make(Echomail::class));
|
|
});
|
|
|
|
$service->extend('netmail', function ($app) {
|
|
return new NetmailChannel($app->make(Netmail::class));
|
|
});
|
|
|
|
$service->extend('matrix', function ($app) {
|
|
return new MatrixChannel($app->make(Echomail::class));
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
static::bootSingleOrFail();
|
|
|
|
// Add our page assets
|
|
Blade::directive('pa',function($expression) {
|
|
return sprintf('<?php PageAssets::asset(\'%s\') ?>',$expression);
|
|
});
|
|
|
|
Auth::viaRequest('matrix-token',function (Request $request) {
|
|
return (config('matrix.hs_token') && ($request->bearerToken() === config('matrix.hs_token'))) ? TRUE : NULL;
|
|
});
|
|
|
|
// Mailer Admin
|
|
Gate::define('admin',fn(User $o)=>($o->admin === TRUE));
|
|
|
|
// ZC of a Zone
|
|
Gate::define('zc',fn(User $o)=>(($o->admin === TRUE) || $o->ZC()));
|
|
|
|
Event::listen(
|
|
Message::class,
|
|
MessageListener::class,
|
|
);
|
|
|
|
// @todo This should be detected automatically?
|
|
Event::listen(
|
|
EchomailEvent::class,
|
|
EchomailListener::class,
|
|
);
|
|
}
|
|
}
|