inhere / php-sroute Goto Github PK
View Code? Open in Web Editor NEWA very lightweight and fast speed PHP request router. 非常快速且轻量的请求匹配路由器。无依赖、简洁、自定义性强,查找匹配速度快
Home Page: https://inhere.github.io/php-sroute/
License: MIT License
A very lightweight and fast speed PHP request router. 非常快速且轻量的请求匹配路由器。无依赖、简洁、自定义性强,查找匹配速度快
Home Page: https://inhere.github.io/php-sroute/
License: MIT License
现有的params匹配格式是{var},能自定义就好了,如:
:var , <var>
nginx和Apache的规则是啥
require('static/Route/RouterInterface.php');
require('static/Route/SRouter.php');
require('static/Route/RouterConfigTrait.php');
require('static/Route/Router.php');
HP Fatal error: Uncaught Error: Class 'Inhere\Route\Route' not found i
各种报错 新手难入手啊 说明文档能详细点吗?
https://www.demo.cn//index.php?m=ke
这样的地址将出现错误,如何解决。
[15-May-2020 11:54:27 Asia/Shanghai] PHP Fatal error: Uncaught TypeError: Argument 1 passed to Inhere\Route\Router::match() must be of the type string, null given, called in /www/wwwroot/php.cn/vendor/inhere/sroute/src/Dispatcher/SimpleDispatcher.php on line 136 and defined in /www/wwwroot/php.cn/vendor/inhere/sroute/src/Router.php:383
Stack trace:
#0 /www/wwwroot/php.cn/vendor/inhere/sroute/src/Dispatcher/SimpleDispatcher.php(136): Inhere\Route\Router->match(NULL, 'GET')
#1 /www/wwwroot/php.cn/vendor/inhere/sroute/src/Router.php(555): Inhere\Route\Dispatcher\SimpleDispatcher->dispatchUri(NULL, 'GET')
#2 /www/wwwroot/php.cn/index.php(62): Inhere\Route\Router->dispatch()
#3 {main}
thrown in /www/wwwroot/php.cn/vendor/inhere/sroute/src/Router.php on line 383
在不添加任何路由的情况下,提供两个参数(地址/路径,规则)直接进行匹配:如:
$router->match(url,rule);
or
$router->match(path,rule);
这是代码:
<?php
/**
* Created by PhpStorm.
* User: Administrator
*/
require("vendor/autoload.php");
use Inhere\Route\ORouter;
use Inhere\Route\Dispatcher\Dispatcher;
$router = new ORouter();
$router->get('/', function() {
echo 'hello';
});
$router->get('/index',Controllers\IndexController::class);
$dispatcher = new Dispatcher([
'dynamicAction' => true,
]);
$router->dispatch($dispatcher);
当访问/
时候好用,访问 /index
就出现 page not found ,所有的类都加载了,这错误是怎么回事?
use Inhere\Route\Router;
$router = new Router();
print_r($router);
$router->get('/', function() {
echo 'hello';
});
php 7.3.4
$router->group('/grp', function (Router $r) use (&$r1) {
$r1 = $r->get('/path', 'h0')->push('func2');
}, ['func3', 'func4'], ['n1' => 'v1']);
例如func3,传进去的是字符串吗,在哪里注册的
<?php
error_reporting(E_ALL | E_STRICT);
date_default_timezone_set('Asia/Shanghai');
$libDir = dirname(__FILE__);
if (file_exists($libDir . '/vendor/autoload.php')) {
require $libDir . '/vendor/autoload.php';
}
use Inhere\Route\Router;
$router = new Router();
$router->get('/', function() {
echo 'hello';
});
// Not in group
if (!$this->currentGroupPrefix) {
return;
}
middleware,use 在路由中都不生效
只有在group里的单个路由才生效
// Prepend group middleware at before.
if ($this->currentGroupChains) {
$route->setChains(array_merge($this->currentGroupChains, $route->getChains()));
}
数组合并是不是用问题,不知道设计是几维数组,middleware 都是一维数组嘛??
Route::use(['api'])->group('/api', function () {
Route::get('/test', \app\controller\IndexController::class . '@index')->middleware(['api1']);
},['api2','api3']);
dump 的middleware $router->getChains()
array(3) {
[0]=>
string(4) "api2"
[1]=>
string(4) "api3"
[2]=>
array(1) {
[0]=>
string(4) "api1"
}
}
<?php
error_reporting(E_ALL | E_STRICT);
date_default_timezone_set('Asia/Shanghai');
$libDir = dirname(__FILE__);
if (file_exists($libDir . '/vendor/autoload.php')) {
require $libDir . '/vendor/autoload.php';
}
use Inhere\Route\Router;
$router = new Router();
$router->get('/', function() {
echo 'hello';
});
$router->get('/', 'HomeController@index');//使用控制器
$router->dispatch();//开始调度
HomeController应该在什么路径才可以访问?
你好,我按照你的方法调用返回404,查看了下源码
public function dispatch($dispatcher = null, string $path = '', string $method = '')
{
if (!$dispatcher) {
$dispatcher = new Dispatcher;
} elseif (is_array($dispatcher)) {
$dispatcher = new Dispatcher($dispatcher);
}
if (!$dispatcher instanceof DispatcherInterface) {
throw new InvalidArgumentException(
'The first argument is must an array OR an object instanceof the DispatcherInterface'
);
}
if (!$dispatcher->hasRouter()) {
$dispatcher->setRouter($this);
}
return $dispatcher->dispatchUri($path, $method);
}
最后的$path, $method这两个参数为空,首页直接$router->dispatch()调用之后发现没有参数传入,我手动填了之后就起作用了,
新手不懂的地方请见谅
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.