forked from flyimg/flyimg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.php
81 lines (67 loc) · 1.98 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
<?php
use Core\Resolver\ControllerResolver;
use Core\Service\CoreManager;
use Core\Service\ImageProcessor;
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('UPLOAD_WEB_DIR', 'uploads/');
define('UPLOAD_DIR', __DIR__.'/web/'.UPLOAD_WEB_DIR);
define('TMP_DIR', __DIR__.'/var/tmp/');
define('LOG_DIR', __DIR__.'/var/log/');
define('ROOT_DIR', __DIR__);
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(__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',
)
);
/** Controller Resolver */
$app['resolver'] = function ($app) {
return new ControllerResolver($app, $app['logger']);
};
/** Image processor Service */
$app['image.processor'] = function ($app) {
return new ImageProcessor($app['flysystems']['upload_dir']);
};
/** Core Manager Service */
$app['core.manager'] = function ($app) {
return new CoreManager($app['image.processor'], $app['params']);
};
/** debug conf */
$app['debug'] = $app['params']['debug'];
return $app;