-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbootstrap.php
39 lines (28 loc) · 1009 Bytes
/
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
<?php
spl_autoload_register(function($class){
$class_path = __DIR__.'/lib/'.str_replace('\\', '/', $class).'.php';
if(file_exists($class_path)) include_once($class_path);
});
$this->module('cockpitql')->extend([
'query' => function($query = '{}', $variables = null) {
return \CockpitQL\Query::process($query, $variables);
}
]);
// ADMIN
if (COCKPIT_ADMIN && !COCKPIT_API_REQUEST) {
include_once(__DIR__.'/admin.php');
}
// REST
if (COCKPIT_API_REQUEST) {
$app->on('cockpit.rest.init', function($routes) use($app) {
$routes['graphql'] = 'CockpitQL\\Controller\\RestApi';
});
// allow access to public graphql query
$app->on('cockpit.api.authenticate', function($data) {
if ($data['user'] || $data['resource'] != 'graphql') return;
if ($this->retrieve('config/cockpitql/publicAccess', false)) {
$data['authenticated'] = true;
$data['user'] = ['_id' => null, 'group' => 'public'];
}
});
}