/
WebAppBindingModule.php
88 lines (83 loc) · 2.19 KB
/
WebAppBindingModule.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
<?php
/**
* This file is part of stubbles.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package net\stubbles\webapp
*/
namespace net\stubbles\webapp\ioc;
use net\stubbles\ioc\Binder;
use net\stubbles\ioc\module\BindingModule;
use net\stubbles\lang\BaseObject;
use net\stubbles\webapp\UriConfigurator;
use net\stubbles\webapp\auth\AuthConfiguration;
/**
* Binding module for web applications.
*
* @since 1.7.0
*/
class WebAppBindingModule extends BaseObject implements BindingModule
{
/**
* url configuration
*
* @type UriConfigurator
*/
private $uriConfigurator;
/**
* auth configuration
*
* @type AuthConfigurator
*/
private $authConfigurator;
/**
* constructor
*
* @param UriConfigurator $uriConfigurator
*/
public function __construct(UriConfigurator $uriConfigurator)
{
$this->uriConfigurator = $uriConfigurator;
}
/**
* static constructor
*
* @param UriConfigurator $uriConfig
* @return WebAppBindingModule
*/
public static function create(UriConfigurator $uriConfig)
{
return new self($uriConfig);
}
/**
* enable auth processor
*
* @return AuthConfigurator
*/
public function enableAuth()
{
$this->authConfigurator = new AuthConfiguration();
return $this->authConfigurator;
}
/**
* configure the binder
*
* @param Binder $binder
*/
public function configure(Binder $binder)
{
if (null !== $this->authConfigurator) {
$binder->bind('net\\stubbles\\webapp\\auth\\AuthConfiguration')
->toInstance($this->authConfigurator);
}
$binder->bind('net\\stubbles\\webapp\\UriConfiguration')
->toInstance($this->uriConfigurator->getConfig());
$binder->bindConstant('net.stubbles.webapp.resource.handler')
->to($this->uriConfigurator->getResourceHandler());
$binder->bindConstant('net.stubbles.webapp.resource.mime.types')
->to($this->uriConfigurator->getResourceMimeTypes());
}
}
?>