-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMicrobe.php
146 lines (122 loc) · 5.31 KB
/
Microbe.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
<?php
namespace WernerDweight\Microbe;
use WernerDweight\Dobee\Dobee;
use WernerDweight\MicrobeImageManager\Utils\ImageManagerUtility;
use WernerDweight\Microbe\framework\kernel\Kernel;
use WernerDweight\Microbe\framework\router\Router;
use WernerDweight\Microbe\framework\canonicalizer\Canonicalizer;
use WernerDweight\Microbe\framework\tokenizer\Tokenizer;
use WernerDweight\Microbe\framework\translator\Translator;
use WernerDweight\Microbe\framework\twig\AssetExtension;
use WernerDweight\Microbe\framework\twig\CanonicalizeExtension;
use WernerDweight\Microbe\framework\twig\PathExtension;
use WernerDweight\Microbe\framework\twig\RenderExtension;
use WernerDweight\Microbe\framework\twig\GeneralExtension;
use WernerDweight\Microbe\framework\twig\TextFunctionsExtension;
use WernerDweight\Microbe\framework\twig\TranslateExtension;
use WernerDweight\Microbe\framework\parenhancer\Parenhancer;
use WernerDweight\Microbe\framework\gatekeeper\Gatekeeper;
use WernerDweight\Microbe\framework\formbuilder\Twig\Extension\FormExtension;
use WernerDweight\Microbe\framework\flashmessenger\FlashMessenger;
class Microbe{
public function __construct($configuration = [], $env = 'prod'){
/// initialize parameters enhancer
$parenhancer = new Parenhancer(str_replace('%env%',$env,$configuration['parameters']['path']));
$configuration = $parenhancer->enhanceArray($configuration);
/// initialize twig
\Twig_Autoloader::register();
$loader = new \Twig_Loader_Filesystem($configuration['twig']['pathToTemplates']);
$twig = new \Twig_Environment($loader, [
'cache' => $env !== 'prod' ? false : $configuration['twig']['pathToCache'],
]);
/// initialize dobee
$dobee = null;
if(isset($configuration['dobee']) && $configuration['dobee']['enable'] === true){
$dobee = new Dobee(
$parenhancer->enhance(
file_get_contents($configuration['dobee']['pathToConfiguration'])
),
$configuration['dobee']['pathToEntities'],
$configuration['dobee']['entityNamespace']
);
}
/// initialize image manager
$imageManager = null;
if(isset($configuration['wd_image_manager']) && $configuration['wd_image_manager']['enable'] === true){
$imageManager = new ImageManagerUtility([
'versions' => $configuration['wd_image_manager']['versions'],
'upload_root' => $configuration['wd_image_manager']['upload_root'],
'upload_path' => $configuration['wd_image_manager']['upload_path'],
'secret' => $configuration['wd_image_manager']['secret'],
]);
}
/// initialize mailer
$mailer = null;
$mailerConfig = $configuration['swiftmailer'];
if(isset($mailerConfig) && isset($mailerConfig['enable']) && $mailerConfig['enable'] === true){
$transport = \Swift_MailTransport::newInstance();
if (isset($mailerConfig['transport']) && $mailerConfig['transport'] === 'smtp') {
$transport = \Swift_SmtpTransport::newInstance(
isset($mailerConfig['host']) ? $mailerConfig['host'] : null,
isset($mailerConfig['port']) ? $mailerConfig['port'] : null,
isset($mailerConfig['encryption']) ? $mailerConfig['encryption'] : null
);
if (isset($mailerConfig['auth_mode'])) {
$transport = $transport->setAuthMode($mailerConfig['auth_mode']);
}
if (isset($mailerConfig['username'])) {
$transport = $transport->setUsername($mailerConfig['username']);
}
if (isset($mailerConfig['password'])) {
$transport = $transport->setPassword($mailerConfig['password']);
}
}
$mailer = \Swift_Mailer::newInstance($transport);
}
/// initialize gatekeeper
$gatekeeper = Gatekeeper::getInstance();
/// initialize flashmessenger
$flashmessenger = FlashMessenger::getInstance();
/// initialize router
$router = new Router($configuration['router']['path'],$configuration['router']['firewall'],$gatekeeper->getRole());
/// initialize translator
$translator = null;
if(isset($configuration['translator']) && $configuration['translator']['enable'] === true){
$translator = new Translator($configuration['translator']['paths']);
$twig->addExtension(new TranslateExtension($translator));
}
/// add twig extensions
$twig->addExtension(new AssetExtension(
$router,
$configuration['environment'],
$configuration['theme']
));
$twig->addExtension(new CanonicalizeExtension);
$twig->addExtension(new PathExtension($router));
$twig->addExtension(new RenderExtension($router));
$twig->addExtension(new FormExtension($twig,$translator));
$twig->addExtension(new GeneralExtension);
$twig->addExtension(new TextFunctionsExtension);
/// initialize canonicaler
$canonicalizer = new Canonicalizer;
/// initialize tokenizer
$tokenizer = new Tokenizer;
/// create an array of services to be passed to the application
$services = [
'twig' => $twig,
'dobee' => $dobee,
'imageManager' => $imageManager,
'mailer' => $mailer,
'router' => $router,
'canonicalizer' => $canonicalizer,
'tokenizer' => $tokenizer,
'parenhancer' => $parenhancer,
'gatekeeper' => $gatekeeper,
'flashmessenger' => $flashmessenger,
'translator' => $translator,
];
/// run app
$kernel = new Kernel($services,$configuration);
}
}
?>