forked from Rareloop/primer
/
index.php
53 lines (43 loc) · 1.33 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
require 'vendor/autoload.php';
// Create a Primer instance
$primer = require_once __DIR__.'/bootstrap/start.php';
// Create a router object
$router = new AltoRouter();
/**
* Match the home page, show the full list of patterns
*/
$router->map('GET', '/', function () use ($primer) {
$primer->showAllPatterns(!isset($_GET['minimal']));
});
/**
* Match the routes for showing individual patterns
*/
$router->map('GET', '/patterns/[**:trailing]', function ($ids) use ($primer) {
// Enable multiple patterns to be displayed, seperated by ':' characters
$ids = explode(':', $ids);
// Show the patterns
$primer->showPatterns($ids, !isset($_GET['minimal']));
});
/**
* Match the routes for showing specific templates
*/
$router->map('GET', '/templates/[**:trailing]', function ($id) use ($primer) {
// Show the template
$primer->showTemplate($id);
});
/**
* Match the routes for retrieving the list of page templates
*/
$router->map('GET', '/menu', function () use ($primer) {
// Show the template
$primer->showMenu();
});
// Match current request url
$match = $router->match();
// Call closure or throw 404 status
if ($match && is_callable($match['target'])) {
call_user_func_array($match['target'], $match['params']);
} else {
throw new Exception('A route could not be found to match your request');
}