forked from grocy/grocy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.php
68 lines (56 loc) · 1.73 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
<?php
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Container\ContainerInterface as Container;
use Slim\Factory\AppFactory;
use Grocy\Helpers\UrlManager;
use Grocy\Controllers\LoginController;
// Load composer dependencies
require_once __DIR__ . '/vendor/autoload.php';
// Load config files
require_once GROCY_DATAPATH . '/config.php';
require_once __DIR__ . '/config-dist.php'; // For not in own config defined values we use the default ones
// Definitions for dev/demo/prerelease mode
if ((GROCY_MODE === 'dev' || GROCY_MODE === 'demo' || GROCY_MODE === 'prerelease') && !defined('GROCY_USER_ID'))
{
define('GROCY_USER_ID', 1);
}
// Definitions for disabled authentication mode
if (GROCY_DISABLE_AUTH === true)
{
if (!defined('GROCY_USER_ID'))
{
define('GROCY_USER_ID', 1);
}
}
// Setup base application
AppFactory::setContainer(new DI\Container());
$app = AppFactory::create();
$container = $app->getContainer();
$container->set('view', function(Container $container)
{
return new Slim\Views\Blade(__DIR__ . '/views', GROCY_DATAPATH . '/viewcache');
});
$container->set('LoginControllerInstance', function(Container $container)
{
return new LoginController($container, 'grocy_session');
});
$container->set('UrlManager', function(Container $container)
{
return new UrlManager(GROCY_BASE_URL);
});
$container->set('ApiKeyHeaderName', function(Container $container)
{
return 'GROCY-API-KEY';
});
// Load routes from separate file
require_once __DIR__ . '/routes.php';
// Set base path if defined
if (!empty(GROCY_BASE_PATH))
{
$app->setBasePath(GROCY_BASE_PATH);
}
// Add default middleware
$app->addRoutingMiddleware();
$app->addErrorMiddleware(true, false, false);
$app->run();