-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
ServiceProvider.php
59 lines (54 loc) · 1.78 KB
/
ServiceProvider.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
<?php
namespace Coyote\Providers\Neon;
use Illuminate\Database\DatabaseManager;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Session\Middleware\StartSession;
use Neon\Application;
use Neon\Laravel;
use Neon\Laravel\JobOffers;
use Neon\Laravel\LaravelVisitor;
use Neon\Persistence;
use Neon\StaticEvents;
class ServiceProvider extends RouteServiceProvider
{
public function register(): void
{
parent::register();
$this->app->instance(
Application::class,
new Application('4programmers.net',
$this->attendance(),
new JobOffers(),
new StaticEvents(),
new LaravelVisitor($this->app),
new Laravel\CoyoteSystem($this->app),
));
}
public function loadRoutes(): void
{
$this
->get('/events', [
'uses' => function (Request $request) {
/** @var Application $application */
$application = $this->app->get(Application::class);
return $application->html($this->startSessionGetCsrf($request));
},
])
->middleware('neon');
}
private function attendance(): Persistence\Attendance
{
/** @var DatabaseManager $database */
$database = $this->app->get(DatabaseManager::class);
return new Laravel\Attendance($database);
}
private function startSessionGetCsrf(Request $request): string
{
/** @var StartSession $middleware */
$middleware = $this->app->get(StartSession::class);
$middleware->handle($request, fn() => new Response(''));
return session()->token() ?? '';
}
}