This repository was archived by the owner on Feb 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
64 lines (53 loc) · 1.74 KB
/
Copy pathindex.php
File metadata and controls
64 lines (53 loc) · 1.74 KB
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
<?php
include __DIR__ . '/../vendor/autoload.php';
use MinorWork\App;
$app = new App();
$app->handlerAlias([
'lookFor' => 'ExampleController:lookingFor',
]);
$app->setRouting([
'root' => ['/', 'itWorks'],
'basic' => ['itWorks'],
'params' => ['/p/{b1:\d+}[/{b2}]', 'itWorks'],
'controller' => ['/c/{action}', ['itWorks', 'ExampleController:lookingFor']],
'aliased' => ['/a/{action}', ['itWorks', 'lookFor']],
'simpleview' => ['simpleView'],
'redirect' => ['/r/{name}', function($app, $params){
$app->redirectTo($params['name'], $app->get('_GET'));
}],
// 'default' => [function($app, $params){echo "Override default handler!";}],
]);
$app->run();
exit;
/////////////////////////////////////////
function simpleView($app, $params)
{
$app->view->prepare(
'I am a {job}, not a {not_my_job}.',
['job' => 'Doctor', 'not_my_job' => 'mechanic']
);
}
function itWorks($app, $params)
{
$template = <<<TEMPLATE
<pre><hr>[Links]
<a href='/basic'>/basic</a> The basic.
<a href='/p/12345/ParamForB'>/p/12345/ParamForB</a> URL parameters.
<a href='/not_exist'>/not_exist</a> Fallback to default handler when no match found.
<a href='/c/love'>/c/love</a> Controller class example.
<a href='/a/magic'>/a/magic</a> Aliased request handler
<a href='/simpleview'>/simpleview</a> SimpleView
<a href='/r/controller?action=peace'>/r/controller?action=peace</a> Supports named redirection.
<hr>[params]
TEMPLATE;
$template .= json_encode($params, JSON_PRETTY_PRINT);
$app->view->prepare($template);
}
class ExampleController
{
public function lookingFor($app, $params)
{
$view = $app->view;
$view->prepare("{$view}<hr>You are looking for {$params['action']}");
}
}