-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathobject.php
More file actions
83 lines (66 loc) · 1.67 KB
/
object.php
File metadata and controls
83 lines (66 loc) · 1.67 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php declare(strict_types=1);
/**
* Created by PhpStorm.
* User: inhere
* Date: 2017/7/14
* Time: 下午9:12
*
* you can test use:
* php -S 127.0.0.1:5671 example/object.php
*
* then you can access url: http://127.0.0.1:5671
*/
use Inhere\Route\Dispatcher\Dispatcher;
use Inhere\Route\Router;
require dirname(__DIR__) . '/test/boot.php';
$router = new Router;
// set config
$router->config([
// 'ignoreLastSlash' => true,
// 'tmpCacheNumber' => 100,
// enable autoRoute
// you can access '/demo' '/admin/user/info', Don't need to configure any route
'autoRoute' => 1,
'controllerNamespace' => 'Inhere\RouteTest\Controllers',
'controllerSuffix' => 'Controller',
]);
$router->get('/routes', function () {
global $router;
echo "<pre><code>{$router->__toString()}</code></pre>";
});
$hasRouter = true;
require __DIR__ . '/some-routes.php';
// $router->rest('/rest', RestController::class);
// $router->any('*', function () {
// echo "This is fallback handler\n";
// });
// var_dump($router);die;
$dispatcher = new Dispatcher([
'dynamicAction' => true,
// on notFound, output a message.
Dispatcher::ON_NOT_FOUND => function ($path) {
echo "the page $path not found!";
}
]);
// OR register event by `Dispatcher::on()`
// $dispatcher->on(Dispatcher::ON_NOT_FOUND, function ($path) {
// echo "the page $path not found!";
// });
/*
method 1
$dispatcher->setRouter($router);
$dispatcher->dispatch();
*/
/*
method 2
*/
$router->dispatch($dispatcher);
/*
method 3
$router->dispatch([
'dynamicAction' => true,
Dispatcher::ON_NOT_FOUND => function ($path) {
echo "the page $path not found!";
}
]);
*/