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
|
<?php
use app\controllers\Resolve;
use app\controllers\Product;
// Home/Welcome
// ---
Route::add('/', function() { // echo 'Welcome!'; });
header('Location: /eidi-artozacharoplasteioy/psomi-artoskeyasmata', true, 302);
});
// Error Pages
// ---
Route::notFound( function() {
header("HTTP/1.0 404 Not Found");
render_view('error/404', ['message' => 'nobody knows it (but you got a secret smile;)']);
}); // 404
// Resolve friendly urls
// ---
Route::add('/([0-9a-zA-Z-_]*)',
function($a) { Resolve::url([$a]); }
);
Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)',
function($a, $b) { Resolve::url([$a, $b]); }
);
Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)',
function($a, $b, $c) { Resolve::url([$a, $b, $c]); }
);
// 4-th level paths belong to products
// ---
Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)',
function($a, $b, $c, $d) { Product::fromUrl($d, [$a, $b, $c]); }
);
/** URL-format Proposal:
* -----------------------------------------------------------------------------
*
* Page (almost-static content):
* /about/{url}
# Route::add('/about/([0-9a-zA-Z-_\/]*)', function($url) { Page::fromUrl($url); });
*
* Product:
* /{level-1}/{level-2}/{level-3}/{friendly-url}-{id}
# Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)-([0-9]*)',
# function($category, $subcategory, $group, $label, $id) {
# Product::fromID([$$category, $subcategory, $group, $label], $id);
# }
# );
*
* Category
* /{category}/[ {subcategory}[ /{group}]]
Route::add('/([0-9a-zA-Z-_]*)', function($a) { Category::url([$a]); };
Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b) { Category::url([$a, $b]); });
Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b, $c) { Category::url([$a, $b, $c]); });
* -----------------------------------------------------------------------------
*/
/* EXAMPLES (use it for brainsrtorming)
* -----------------------------------------------------------------------------
*
// Typical Use
// ---
Route::add('/art', function() { Art::blah(); });
Route::add('/art/db', function() { Art::fromDatabase(); });
Route::add('/art/([0-9]*)', function($id) { Art::getInfo($id); });
// Get-Post route example
// ---
Route::add('/contact-form', function() {
echo '<form method="post"><input type="text" name="test" /><input type="submit" value="send" /></form>';
}, 'get');
Route::add('/contact-form', function() {
echo 'Hey! The form has been sent:<br/>'; print_r($_POST);
}, 'post');
// Accept number as parameter
// ---
Route::add('/foo/([0-9]*)/bar', function($var1) {
// echo $var1.' is a number!';
echo "{$var1} is a number!";
});
// About pages
// ---
Route::add('/about/([0-9a-zA-Z-_]*)', function($page) {
InfoPage::render('about/'.page);
});
// handle a request like: /foo/123/bar/3254-lefki-zaxari-marata-1kg
// where first-numeric-part of last-uri-section (3254) is the product number
// ---
Route::add('/foo/([0-9]*)/bar/([0-9]*)-([0-9a-zA-Z-_]*)', function($num, $id, $name) {
echo $num .' is some nomber, id = '. $id .' and label = '. $name;
});
// handle a request like: /zaxares-glykantika/lefki-zaxari-year-2022-45678
// where last-numeric-part of last-uri-section (45678) is the product number
// ---
Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)-([0-9]*)',
function($category, $subcategory, $group, $label, $id) {
Shop::product([$$category, $subcategory, $group, $label], $id);
});
// last chance to resolve (some friendly url)
// ---
Route::add('/([0-9a-zA-Z-_]*)', function($a) { Resolve::uri([$a]); });
Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b) { Resolve::uri([$a, $b]); });
Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)', function($a, $b, $c) { Resolve::uri([$a, $b, $c]); });
// Product page
// handle a request like: /pantopoleio/zaxares/lefki-zaxari/lefki-zaxari-year-2022-45678
// where last-numeric-part of last-uri-section (45678) is the product number
// ---
Route::add('/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)/([0-9a-zA-Z-_]*)-([0-9]*)',
function($category, $subcategory, $group, $label, $id) {
Shop::product([$$category, $subcategory, $group, $label], $id);
});
* ------------------------------------------------------------------------------
*/
|