-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
74 lines (59 loc) · 2.19 KB
/
index.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
<?php
/**
* Leadaki Frontend Application
*
* @author Jesús Urrutia <me@jesusurrutia.com>
* @description Load data from remote API and display with Twig template system
*/
// -- Load composer autoload
require __DIR__ . '/vendor/autoload.php';
// -- Load used class
use Leadaki\Frontend\Service\LoadSiteDataService;
use Leadaki\Frontend\Service\LoadUrlConfigService;
use Leadaki\Frontend\Application\Application;
use Leadaki\Frontend\Service\AltoRouterService;
use Leadaki\Frontend\Service\TwigTemplateService;
use Leadaki\Frontend\Twig\ApplicationTwigExtension;
// -- Load config file or redirect to install script
if (file_exists(__DIR__ . '/config/config.php')) {
require __DIR__ . '/config/config.php';
} else {
header('Location: install/');
}
// -- Load config from url
$loadUrlConfigService = new LoadUrlConfigService($config, $_SERVER['REQUEST_URI']);
$config['app']['website_id'] = $loadUrlConfigService->getWebsiteId();
// -- Load remote data
$loadSiteDataService = new LoadSiteDataService(
$config['api']['base_url'] . '/' . $config['app']['website_id'],
array(
'cacheFolder' => $config['folders']['cache'],
'cacheValid' => 3600,
)
);
$site = $loadSiteDataService->getSite();
$site->getTemplate()->setId($loadUrlConfigService->getTemplate());
$site->getTemplate()->setColor($loadUrlConfigService->getColor());
$routerService = new AltoRouterService(array(
'base_path' => parse_url($config['app']['base_url'], PHP_URL_PATH)
));
$templateService = new TwigTemplateService(array(
'templates_folder' => $config['folders']['templates'],
'templates_cache_folder' => $config['folders']['templates_cache'],
'debug' => $config['app']['debug'],
));
$templateService->addGlobal('config', $config);
$templateService->addGlobal('site', $site);
$templateService->addExtension(new Twig_Extensions_Extension_Text());
$templateService->addExtension(new Twig_Extensions_Extension_Array());
$templateService->addExtension(new ApplicationTwigExtension($config, $routerService));
if ($config['app']['debug']) {
$templateService->addExtension(new Twig_Extension_Debug());
}
$app = new Application(
$routerService,
$templateService,
$config,
$site
);
$app->run();