-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.file
56 lines (50 loc) · 1.54 KB
/
example.file
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
<?php
require __DIR__.'/vendor/autoload.php';
$app = Base::instance();
$app->mset(array(
'DEBUG' => 3,
'DB' => new DB\Jig('storage/db/', DB\Jig::FORMAT_JSON),
'TOKEN' => array(
'TYPE' => 'HEADER',
'KEY' => 'Authorization',
'STARTS_WITH' => 'X-Auth-Token',
'TABLE' => 'Tokens',
'TABLE_KEY' => 'token'
),
));
abstract class Model extends DB\Cortex { protected $db = 'DB'; }
class User extends Model { protected $table = 'users', $fieldConf = ['email' => ['type' => DB\SQL\Schema::DT_TEXT]]; }
class Tokens extends Model {protected $table = 'tokens', $fieldConf = ['user' => ['belongs-to-one' => 'User'], 'token' => ['type' => DB\SQL\Schema::DT_TEXT]]; }
// GENERATE USER & TOKEN FOR TESTING
/*$uModel1 = new User();
$uModel1->email = '[email protected]';
$uModel1->save();
$uModel2 = new User();
$uModel2->email = '[email protected]';
$uModel2->save();
$tModel1 = new Tokens();
$tModel1->user = $uModel1;
$tModel1->token = 'abcdefghijklmnopqrstuvwxyz';
$tModel1->save();
$tModel2 = new Tokens();
$tModel2->user = $uModel2;
$tModel2->token = '01234567890';
$tModel2->save();*/
$app->route('GET|HEAD /', function($app){
echo "index";
});
$app->route('GET|HEAD /home', function($app){
echo "home";
});
$app->route('GET|HEAD /home/@id', function($app){
echo $app->get('PARAMS.id');
});
$app->route('GET|POST /profile/@id', function($app){
echo $app->get('PARAMS.id');
});
$token = TokenMiddleware::instance();
$token->protect(array('HEAD|GET /home/*', 'POST /profile/*'), function($app, $params, $alias) {
echo 'error';
});
$token->run();
$app->run();