-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathHerbertServiceProvider.php
More file actions
166 lines (138 loc) · 3.9 KB
/
HerbertServiceProvider.php
File metadata and controls
166 lines (138 loc) · 3.9 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php namespace Herbert\Framework\Providers;
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Support\ServiceProvider;
use Illuminate\Cookie\CookieJar;
use Herbert\Framework\Session;
/**
* @see http://getherbert.com
*/
class HerbertServiceProvider extends ServiceProvider {
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerEloquent();
$this->app->instance(
'env',
defined('HERBERT_ENV') ? HERBERT_ENV
: (defined('WP_DEBUG') ? 'local'
: 'production')
);
$this->app->instance(
'http',
\Herbert\Framework\Http::capture()
);
$this->app->alias(
'http',
'Herbert\Framework\Http'
);
$this->app->instance(
'router',
$this->app->make('Herbert\Framework\Router', ['app' => $this->app])
);
$this->app->bind(
'route',
'Herbert\Framework\Route'
);
$this->app->instance(
'enqueue',
$this->app->make('Herbert\Framework\Enqueue', ['app' => $this->app])
);
$this->app->alias(
'enqueue',
'Herbert\Framework\Enqueue'
);
$this->app->instance(
'panel',
$this->app->make('Herbert\Framework\Panel', ['app' => $this->app])
);
$this->app->alias(
'panel',
'Herbert\Framework\Panel'
);
$this->app->instance(
'shortcode',
$this->app->make('Herbert\Framework\Shortcode', ['app' => $this->app])
);
$this->app->alias(
'shortcode',
'Herbert\Framework\Shortcode'
);
$this->app->instance(
'widget',
$this->app->make('Herbert\Framework\Widget', ['app' => $this->app])
);
$this->app->alias(
'widget',
'Herbert\Framework\Widget'
);
$this->app->instance(
'session',
$this->app->make('Herbert\Framework\Session', ['app' => $this->app])
);
$this->app->alias(
'session',
'Herbert\Framework\Session'
);
$this->app->instance(
'notifier',
$this->app->make('Herbert\Framework\Notifier', ['app' => $this->app])
);
$this->app->alias(
'notifier',
'Herbert\Framework\Notifier'
);
$this->app->singleton(
'errors',
function ()
{
return session_flashed('__validation_errors', []);
}
);
$_GLOBALS['errors'] = $this->app['errors'];
}
/**
* Registers Eloquent.
*
* @return void
*/
protected function registerEloquent()
{
global $wpdb;
$capsule = new Capsule($this->app);
if (defined('WP_MUFFIN') && WP_MUFFIN) {
$capsule->addConnection([
'driver' => 'sqlite',
'database' => ':memory:',
'charset' => DB_CHARSET,
'collation' => DB_COLLATE ?: $wpdb->collate,
'prefix' => $wpdb->prefix
]);
} else {
$capsule->addConnection([
'driver' => 'mysql',
'host' => DB_HOST,
'database' => DB_NAME,
'username' => DB_USER,
'password' => DB_PASSWORD,
'charset' => DB_CHARSET,
'collation' => DB_COLLATE ?: $wpdb->collate,
'prefix' => $wpdb->prefix
]);
}
$capsule->setAsGlobal();
$capsule->bootEloquent();
}
/**
* Boots the service provider.
*
* @return void
*/
public function boot()
{
$this->app['session']->start();
}
}