-
Notifications
You must be signed in to change notification settings - Fork 47
/
LumenServiceProvider.php
69 lines (54 loc) · 1.66 KB
/
LumenServiceProvider.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
<?php namespace Develpr\AlexaApp\Provider;
use ReflectionClass;
use Illuminate\Support\ServiceProvider;
class LumenServiceProvider extends ServiceProvider{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->setupConfig();
$reflection = new ReflectionClass($this->app);
$this->app->instance('app.middleware', $this->gatherAppMiddleware($reflection));
$this->app->register('Develpr\AlexaApp\Provider\AlexaServiceProvider');
$this->addRequestMiddlewareToBeginning($reflection);
}
protected function setupConfig()
{
$this->mergeConfigFrom(realpath(__DIR__.'/../../config/alexa.php'), 'alexa');
}
/**
* Add the request middleware to the beginning of the middleware stack on the
* Lumen application instance.
*
* @param \ReflectionClass $reflection
*
* @return void
*/
protected function addRequestMiddlewareToBeginning(ReflectionClass $reflection)
{
$property = $reflection->getProperty('middleware');
$property->setAccessible(true);
$middleware = $property->getValue($this->app);
array_unshift($middleware, 'Develpr\AlexaApp\Http\Middleware\Request');
$property->setValue($this->app, $middleware);
$property->setAccessible(false);
}
/**
* Gather the application middleware besides this one so that we can send
* our request through them, exactly how the developer wanted.
*
* @param \ReflectionClass $reflection
*
* @return array
*/
protected function gatherAppMiddleware(ReflectionClass $reflection)
{
$property = $reflection->getProperty('middleware');
$property->setAccessible(true);
$middleware = $property->getValue($this->app);
return $middleware;
}
}