-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.php
69 lines (59 loc) · 1.86 KB
/
init.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php defined('SYSPATH') or die('No direct script access.');
// Luthier auth route
Route::set('luthier/auth', Luthier::ROUTE_NAMESPACE.'/<action>', array(
'action' => 'login|logout',
))
->defaults(array(
'directory' => 'luthier',
'controller' => 'auth',
'action' => 'login',
));
// Luthier media route
Route::set('luthier/media', Luthier::ROUTE_NAMESPACE.'/media/<file>', array(
'file' => '.+',
))
->defaults(array(
'directory' => 'luthier',
'controller' => 'media',
'action' => 'file',
));
// Primary Luthier route (namespace aliasing, home controller forwarding)
Route::set('luthier', function($uri)
{
// Default to Luthier home page
$defaults = array(
'directory' => '', // will add 'luthier' later
'controller' => 'home',
'action' => 'index',
);
// Compile the URI regex
$regex = Route::compile(Luthier::ROUTE_NAMESPACE.'(/<directory>(/<controller>(/<action>)))');
// Check if URI matches the regex
if ( ! preg_match($regex, $uri, $matches))
return FALSE;
// Use defaults for missing parameters
$params = $matches + $defaults;
// Extract relevant parameters (ignoring numeric keys, etc.)
$directory = $params['directory'];
$controller = $params['controller'];
$action = $params['action'];
// If controller doesn't exist, forward action to home controller
$class = 'Controller_Luthier_'.$directory;
$class .= (empty($directory) ? '' : '_').$controller;
if ( ! class_exists($class))
{
// Use "controller" as the action
$action = $controller;
// Use the home controller
$controller = $defaults['controller'];
}
// Return route parameters, adding 'luthier' to directory
return array(
'directory' => 'luthier/'.$directory,
'controller' => $controller,
'action' => $action,
);
},
// For reverse routing
Luthier::ROUTE_NAMESPACE.'(/<directory>)(/<controller>(/<action>))'
);