app.php
7.15 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
require_once __DIR__.'/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Application Environment
|--------------------------------------------------------------------------
|
| Since our legacy code base use ENV instead of APP_ENV to describe environment,
| we need to map it here so that Laravel understands.
|
*/
putenv('APP_ENV='.(getenv('ENV') ?: 'production'));
/*
|--------------------------------------------------------------------------
| Application Debug Mode
|--------------------------------------------------------------------------
|
| When your application is in debug mode, detailed error messages with
| stack traces will be shown on every error that occurs within your
| application. If disabled, a simple generic error page is shown.
|
*/
getenv('ENV') === 'development' || getenv('ENV') === 'testing' || (isset($_REQUEST['dbug']) && $_REQUEST['dbug'] === 'frsecret') ?
putenv('APP_DEBUG=true') : putenv('APP_DEBUG=false');
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/
$app = new FootyRoom\Support\Application(
realpath(__DIR__.'/../')
);
$app->withFacades(false);
/*
|--------------------------------------------------------------------------
| Register Container Bindings
|--------------------------------------------------------------------------
|
| Now we will register a few bindings in the service container. We will
| register the exception handler and the console kernel. You may add
| your own bindings here if you like or you can make another file.
|
*/
// This is needed because some Lumen classes incorrectly depend on this concrete
// class rather than on contract which does have container binding.
$app->singleton(\Laravel\Lumen\Application::class, function ($app) {
return $app;
});
$app->singleton(
\Illuminate\Contracts\Debug\ExceptionHandler::class,
\FootyRoom\App\Exceptions\Handler::class
);
$app->singleton(
\Illuminate\Contracts\Console\Kernel::class,
\FootyRoom\Console\Kernel::class
);
$app->singleton(\FootyRoom\Support\WebpackAssets::class);
$app->singleton(\FootyRoom\Config::class);
$app->singleton(\FootyRoom\Http\Middleware\StartSession::class);
$app->singleton(\FootyRoom\Repositories\IUserRepository::class, \FootyRoom\Repositories\UserRepository::class);
$app->singleton(\Illuminate\Database\Connection::class, function ($app) {
return $app->make('db')->connection();
});
$app->singleton(\FootyRoom\Support\MongoClient::class);
$app->singleton(\ReCaptcha\ReCaptcha::class, function ($app) {
$config = $app->make(\FootyRoom\Config::class);
return new \ReCaptcha\ReCaptcha($config->get('recaptcha.secret'));
});
// Needed for Validation Factory to be injectable.
$app->bind(\Illuminate\Contracts\Translation\Translator::class, function ($app) {
return $app['translator'];
});
$app->bind(\FootyRoom\Core\Notification\CommentNotifier::class, \FootyRoom\Support\SqlCommentNotifier::class);
// Sessions.
$app->singleton('session', function ($app) {
return $app->loadComponent('session', \Illuminate\Session\SessionServiceProvider::class);
});
$app->singleton('session.store', function ($app) {
return $app->loadComponent('session', \Illuminate\Session\SessionServiceProvider::class, 'session.store');
});
$app->alias('session', \Illuminate\Session\SessionManager::class);
// Cookies.
$app->singleton('cookie', function ($app) {
return $app->loadComponent('session', \Illuminate\Cookie\CookieServiceProvider::class, 'cookie');
});
$app->alias('cookie', \Illuminate\Contracts\Cookie\Factory::class);
$app->alias('cookie', \Illuminate\Contracts\Cookie\QueueingFactory::class);
// Mail.
$app->availableBindings[\Illuminate\Contracts\Mail\Mailer::class] = 'registerMailBindings';
/*
|--------------------------------------------------------------------------
| Load Configuration
|--------------------------------------------------------------------------
|
| Here we will load configuration files needed for operation.
|
*/
/*
|--------------------------------------------------------------------------
| Register Middleware
|--------------------------------------------------------------------------
|
| Next, we will register the middleware with the application. These can
| be global middleware that run before and after each request into a
| route or middleware that'll be assigned to some specific routes.
|
*/
$app->middleware([
\FootyRoom\Http\Middleware\StartSession::class,
// Illuminate\Cookie\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
// Illuminate\Session\Middleware\StartSession::class,
// Illuminate\View\Middleware\ShareErrorsFromSession::class,
\FootyRoom\Http\Middleware\VerifyCsrfToken::class,
\FootyRoom\Http\Middleware\Tracker::class,
\FootyRoom\Http\Middleware\NewRelic::class,
// \FootyRoom\Http\Middleware\Prerender::class,
]);
$app->routeMiddleware([
'auth' => \FootyRoom\Http\Middleware\Auth::class,
'auth.lock.json' => \FootyRoom\Http\Middleware\AuthLockJson::class,
'auth.lock.redirect' => \FootyRoom\Http\Middleware\AuthLockRedirect::class,
'auth.lock.moderator' => \FootyRoom\Http\Middleware\AuthLockModerator::class,
'auth.lock.admin' => \FootyRoom\Http\Middleware\AuthLockAdmin::class,
'cors' => \FootyRoom\Http\Middleware\Cors::class,
'honeypot' => \FootyRoom\Http\Middleware\Honeypot::class,
]);
/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/
$app->register(\FootyRoom\Providers\ViewComposerServiceProvider::class);
$app->register(\FootyRoom\Providers\Auth\AuthServiceProvider::class);
$app->register(\FootyRoom\Providers\ElasticEmailServiceProvider::class);
$app->register(\FootyRoom\Providers\EventServiceProvider::class);
$app->register(\FootyRoom\Providers\DoctrineServiceProvider::class);
if (getenv('APP_ENV') === 'development' &&
$app->make(\FootyRoom\Config::class)->get('debug.barEnabled')
) {
$app->configure('debugbar');
$app->register(Barryvdh\Debugbar\LumenServiceProvider::class);
}
/*
|--------------------------------------------------------------------------
| Load The Application Routes
|--------------------------------------------------------------------------
|
| Next we will include the routes file so that they can all be added to
| the application. This will provide all of the URLs the application
| can respond to, as well as the controllers that may handle them.
|
*/
$app->router->group(['namespace' => 'FootyRoom\Http\Controllers'], function ($router) {
require __DIR__.'/../app/Http/routes.php';
});
return $app;