This repository has been archived by the owner on Dec 4, 2019. It is now read-only.
/
ServiceProvider.php
108 lines (94 loc) · 3.57 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
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
<?php
namespace FluxBB\Server;
use Illuminate\Support\ServiceProvider as Base;
use FluxBB\Core\ActionFactory;
class ServiceProvider extends Base
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('fluxbb.server.core', function ($app) {
$server = new Server(new ActionFactory($app));
$this->registerActions($server);
return $server;
});
$this->app->singleton('FluxBB\Server\ServerInterface', function ($app) {
return $app->make('fluxbb.server.core');
});
$this->app->extend('FluxBB\Server\ServerInterface', function ($server, $app) {
$validator = new RequestValidator($app, $server);
$this->registerValidators($validator);
return $validator;
});
$this->app->extend('FluxBB\Server\ServerInterface', function ($server, $app) {
$authorization = new AuthorizationServer($app, $server);
$this->registerAuthorizers($authorization);
return $authorization;
});
}
/**
* Register the actions with the server.
*
* @param \FluxBB\Server\Server $server
* @return void
*/
protected function registerActions(Server $server)
{
$server->registerAction('category', 'FluxBB\Actions\ViewCategory');
$server->registerAction('conversation', 'FluxBB\Actions\GetConversation');
$server->registerAction('post', 'FluxBB\Actions\GetPost');
$server->registerAction('handle_registration', 'FluxBB\Actions\CreateUser');
$server->registerAction('handle_login', 'FluxBB\Actions\Login');
$server->registerAction('logout', 'FluxBB\Actions\Logout');
$server->registerAction('post_edit_handler', 'FluxBB\Actions\EditPost');
$server->registerAction('reply_handler', 'FluxBB\Actions\Reply');
$server->registerAction('topic_subscribe', 'FluxBB\Actions\SubscribeTopic');
$server->registerAction('topic_unsubscribe', 'FluxBB\Actions\UnsubscribeTopic');
$server->registerAction('new_topic_handler', 'FluxBB\Actions\NewTopic');
$server->registerAction('admin.options.set', 'FluxBB\Actions\SetOptions');
$server->registerAction('get.settings', 'FluxBB\Actions\GetSettings');
}
/**
* Register all validators with the request validator.
*
* @param \FluxBB\Server\RequestValidator $validator
* @return void
*/
protected function registerValidators(RequestValidator $validator)
{
$validator->registerValidator('post_edit_handler', 'FluxBB\Validator\PostValidator');
$validator->registerValidator('reply_handler', 'FluxBB\Validator\PostValidator');
$validator->registerValidator('new_topic_handler', 'FluxBB\Validator\PostValidator');
$validator->registerValidator('admin.options.set', 'FluxBB\Validator\OptionsValidator');
$validator->registerValidator('handle_registration', 'FluxBB\Validator\UserValidator');
}
/**
* Register all authorizer with the authorization server.
*
* @param \FluxBB\Server\AuthorizationServer $auth
* @return void
*/
protected function registerAuthorizers(AuthorizationServer $auth)
{
//
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return ['FluxBB\Server\ServerInterface'];
}
}