php require vendor autoload php use flight Engine app new Engine app-

 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
<?php
require 'vendor/autoload.php';
use flight\Engine;
$app = new Engine();
$app->register('pdo', 'PDO',
array('mysql:host=localhost;dbname=test', 'root', '',
array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
)
)
);
$app->register('fenom', 'Fenom::factory',
array(
'resource/views',
'resource/cache',
array(
'auto_reload' => true
)
)
);
$app->route('/', function() use($app) {
$request = $app->request();
if ($request->data->send && !empty($request->data->code)) {
$hash = substr(str_shuffle(uniqid('qwertyuiopasdfghjklzxcvbnm')), 0, 9);
$query = $app->pdo()
->prepare("insert into `codes` (`code`, `hash`, `time`) values (?, ?, now())");
$query->execute(array($request->data->code, $hash));
$app->redirect('/' . $hash);
}
$app->fenom()->display('home.phtml');
});
$app->route('/@hash:[a-z0-9]{9}', function($hash) use($app) {
$query = $app->pdo()->prepare("select * from `codes` where `hash` = ?");
$query->execute(array($hash));
$code = $query->fetch();
if ($code) {
$app->fenom()->display('code.phtml', array(
'code' => $code
));
} else $app->redirect('/');
});
$app->start();