-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.php
189 lines (162 loc) · 6.08 KB
/
app.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
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
<?php
$loader = include_once __DIR__ . '/vendor/autoload.php';
use App\Application;
use App\Saml\ExceptionListener;
use App\Security\ServiceProviderVoter;
use App\Security\UserProvider;
use App\ServiceProvider\CommandsServiceProvider;
use App\ServiceProvider\ControllerServiceProvider;
use App\ServiceProvider\IdentityProviderServiceProvider;
use App\ServiceProvider\RouteServiceProvider;
use App\ServiceProvider\MenuServiceProvider as AppMenuServiceProvider;
use BoxedCode\Silex\Knp\MenuServiceProvider;
use Composer\Autoload\ClassLoader;
use Dflydev\Provider\DoctrineOrm\DoctrineOrmServiceProvider;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Cache\ArrayCache;
use FrostieDE\Silex\EnvironmentServiceProvider;
use FrostieDE\Silex\VersionServiceProvider;
use Igorw\Silex\ConfigServiceProvider;
use Knp\Provider\ConsoleServiceProvider;
use Monolog\Logger;
use Saxulum\DoctrineOrmManagerRegistry\Provider\DoctrineOrmManagerRegistryProvider;
use Silex\Provider\CsrfServiceProvider;
use Silex\Provider\DoctrineServiceProvider;
use Silex\Provider\FormServiceProvider;
use Silex\Provider\MonologServiceProvider;
use Silex\Provider\SecurityServiceProvider;
use Silex\Provider\ServiceControllerServiceProvider;
use Silex\Provider\SessionServiceProvider;
use Silex\Provider\TranslationServiceProvider;
use Silex\Provider\TwigServiceProvider;
use Silex\Provider\ValidatorServiceProvider;
use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\Debug\ExceptionHandler;
use Symfony\Component\Validator\Mapping\Cache\DoctrineCache;
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
if($loader instanceof ClassLoader) {
// Autoload annotations (see http://stackoverflow.com/a/31918150)
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
}
ErrorHandler::register();
$app = new Application();
$app['dir'] = __DIR__;
$app->register(new EnvironmentServiceProvider());
ExceptionHandler::register($app['env'] === 'dev');
$app->register(new ConfigServiceProvider(__DIR__ . '/app/config.yml', [], null, 'config'));
$envConfigFile = __DIR__ . '/app/config.' . $app['env'] . '.yml';
if(file_exists($envConfigFile)) {
$app->register(new ConfigServiceProvider($envConfigFile, [], null, 'config'));
}
$app->register(new VersionServiceProvider(), [
'version.file' => __DIR__ . '/VERSION'
]);
$app->register(new MonologServiceProvider(), [
'monolog.logfile' => __DIR__ . '/var/logs/app.log',
'monolog.level' => $app['debug'] ? Logger::DEBUG : Logger::NOTICE,
'monolog.use_error_handler' => true
]);
$app->register(new DoctrineServiceProvider(), array(
'db.options' => $app['config']['db']
));
$app->register(new DoctrineOrmServiceProvider(), array(
'orm.proxies_dir' => __DIR__ . '/var/doctrine/proxies',
'orm.em.options' => array(
'mappings' => [
[
'type' => 'annotation',
'namespace' => 'App\Entity',
'path' => __DIR__ . '/src/App/Entity',
'use_simple_annotation_reader' => false
]
]
),
));
$app->register(new SessionServiceProvider());
$app->register(new SecurityServiceProvider(), [
'security.firewalls' => [
'unsecured' => [
'pattern' => '^/login$',
'anonymous' => true
],
'secured' => [
'pattern' => '^/',
'form' => [
'login_path' => '/login',
'check_path' => '/login_check'
],
'logout' => [
'logout_path' => '/logout',
'invalidate_session' => true
],
'users' => function() use($app) {
return new UserProvider($app['orm.em']);
}
],
],
'security.role_hierarchy' => [
'ROLE_ADMIN' => [ 'ROLE_USER' ]
]
]);
$app['security.exception_listener._proto'] = $app->protect(function ($entryPoint, $name, $accessDeniedHandler = null) use ($app) {
return function () use ($app, $entryPoint, $name, $accessDeniedHandler) {
return new ExceptionListener(
$app['security.token_storage'],
$app['security.trust_resolver'],
$app['security.http_utils'],
$name,
$app[$entryPoint],
null, // errorPage
$accessDeniedHandler,
$app['logger']
);
};
});
$app->extend('security.voters', function(array $voters) {
$voters[] = new ServiceProviderVoter();
return $voters;
});
$app->register(new TwigServiceProvider(), [
'twig.path' => __DIR__ . '/app/templates',
'twig.options' => [
'cache' => $app['env'] === 'dev' ? false : __DIR__ . '/var/cache/twig',
'auto_reload' => true
],
'twig.form.templates' => [
'bootstrap_3_horizontal_layout.html.twig'
]
]);
$app->register(new ValidatorServiceProvider(), [
'validator.mapping.class_metadata_factory' => function() use ($app) {
$reader = new Doctrine\Common\Annotations\AnnotationReader;
$loader = new Symfony\Component\Validator\Mapping\Loader\AnnotationLoader($reader);
$cache = new DoctrineCache(new ArrayCache());
return new LazyLoadingMetadataFactory($loader, $cache);
}
]);
$app->register(new TranslationServiceProvider(), [
'locale' => 'en',
'translator.domains' => [],
]);
$app->register(new FormServiceProvider());
$app->register(new CsrfServiceProvider());
$app->register(new DoctrineOrmManagerRegistryProvider());
$app->register(new AppMenuServiceProvider());
$app->register(new MenuServiceProvider(), [
'knp_menu.views_path' => __DIR__ . '/vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views/',
'knp_menu.default_renderer' => 'twig'
]);
$app->register(new ServiceControllerServiceProvider());
$app->register(new ControllerServiceProvider());
$app->mount('/', new RouteServiceProvider());
$app->register(new IdentityProviderServiceProvider());
/*
* Console commands
*/
$app->register(new ConsoleServiceProvider(), [
'console.name' => 'Example IdP CLI',
'console.version' => $app['version'],
'console.project_directory' => __DIR__
]);
$app->register(new CommandsServiceProvider());
return $app;