forked from mongodb/laravel-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.php
47 lines (38 loc) · 1.26 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
<?php
$loader = require 'vendor/autoload.php';
$loader->add('', 'tests/models');
$loader->add('', 'tests/seeds');
use Jenssegers\Mongodb\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Container\Container;
use Illuminate\Database\DatabaseManager;
use Illuminate\Database\Connectors\ConnectionFactory;
use Illuminate\Events\Dispatcher;
use Illuminate\Cache\ArrayStore;
use Illuminate\Cache\Repository;
# Fake app class
class App extends ArrayObject {
function bound() {}
}
# Fake app
$app = new App;
# Event dispatcher
$app['events'] = new Dispatcher;
# Cache driver
$app['cache'] = new Repository(new ArrayStore);
# Load database configuration
$config = require 'config/database.php';
foreach ($config as $key => $value)
{
$app['config']["database.$key"] = $value;
}
# Initialize database manager
$app['db.factory'] = new ConnectionFactory(new Container);
$app['db'] = new DatabaseManager($app, $app['db.factory']);
# Extend database manager with reflection hack
$reflection = new ReflectionClass('Jenssegers\Mongodb\Connection');
$app['db']->extend('mongodb', array($reflection, 'newInstance'));
# Static setup
\Jenssegers\Mongodb\Model::setConnectionResolver($app['db']);
\Jenssegers\Eloquent\Model::setConnectionResolver($app['db']);
DB::setFacadeApplication($app);