This repository has been archived by the owner on Apr 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
bootstrap.php
69 lines (54 loc) · 1.91 KB
/
bootstrap.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
<?php
/**
* Silex Skeleton App version 0.1.0
* https://github.com/Ardakilic/silex-skeleton-app
* Arda Kilicdagi <arda@kilicdagi.com>
*/
require_once __DIR__ . '/vendor/autoload.php';
use Silex\Application;
use Symfony\Component\Yaml\Yaml;
use Illuminate\Database\Capsule\Manager as Capsule;
use GuzzleHttp\Client;
//Create the Silex instance
$app = new Application();
//Enable debugging
$app['debug'] = true;
//Enable whoops Service provider to handle errors
if ($app['debug']) {
error_reporting(E_ALL);
ini_set('display_errors', '1');
//Make sure the class exists,
//because this is a dev-dependency and may not be installed
if (class_exists('Whoops\\Provider\\Silex\\WhoopsServiceProvider')) {
$app->register(new Whoops\Provider\Silex\WhoopsServiceProvider());
}
}
//Loading the configuration file
$app['config'] = $app->share(function () {
return Yaml::parse(file_get_contents(__DIR__ . '/app/config.yml'));
});
//This is for proper time handling:
date_default_timezone_set($app['config']['settings']['timezone']);
$app['clients.guzzle'] = $app->share(function () use ($app) {
//Fill with your default parameters such as base_uri etc. of course
return new Client();
});
$app['db'] = $app->share(function () use ($app) {
//Set up Fluent Query Builder..
$capsule = new Capsule;
$capsule->addConnection(
$app['config']['database']['connections'][$app['config']['database']['connection']]
);
return $capsule;
});
//These two have to be outside closure
// Make the Capsule instance available globally via static methods...
$app['db']->setAsGlobal();
// Setup the Eloquent ORM...
$app['db']->bootEloquent();
//Register the controllers:
//Registering the controller service provider
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
$app['foo.controller'] = $app->share(function () use ($app) {
return new App\Controllers\FooController;
});