forked from flyimg/flyimg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.php
70 lines (57 loc) · 1.72 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
<?php
use Core\Resolver\ControllerResolver;
use Core\Service\ImageManager;
use Monolog\Logger;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Routing\Loader\YamlFileLoader;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Yaml\Yaml;
$loader = require_once __DIR__ . '/vendor/autoload.php';
$app = new Silex\Application();
/**
* Define Constants && Load parameters files
*/
define('ROOT_DIR', __DIR__);
define('UPLOAD_DIR', ROOT_DIR . '/var/upload/');
define('TMP_DIR', ROOT_DIR . '/var/tmp/');
define('LOG_DIR', ROOT_DIR . '/var/log/');
if (!is_dir(UPLOAD_DIR)) {
mkdir(UPLOAD_DIR, 0777, true);
}
if (!is_dir(TMP_DIR)) {
mkdir(TMP_DIR, 0777, true);
}
if (!is_dir(LOG_DIR)) {
mkdir(LOG_DIR, 0777, true);
}
$app['params'] = Yaml::parse(file_get_contents(ROOT_DIR . '/config/parameters.yml'));
/**
* Routes
*/
$app['routes'] = $app->extend('routes', function (RouteCollection $routes) {
$loader = new YamlFileLoader(new FileLocator(__DIR__ . '/config'));
$collection = $loader->load('routes.yml');
$routes->addCollection($collection);
return $routes;
});
/**
* Register Storage provider
*/
$app->register(new \Core\Provider\StorageProvider());
/**
* Monolog Service
*/
$app->register(new Silex\Provider\MonologServiceProvider(), array(
'monolog.name' => 'flyimg',
'monolog.level' => Logger::ERROR,
'monolog.logfile' => LOG_DIR . 'dev.log',
));
$app['resolver'] = $app->share(function () use ($app) {
return new ControllerResolver($app, $app['logger']);
});
$app['image.manager'] = $app->share(function ($app) {
return new ImageManager($app['params'], $app['flysystems']['upload_dir']);
});
/** debug conf */
$app['debug'] = $app['params']['debug'];
return $app;