Giter Site home page Giter Site logo

inhere / php-sroute Goto Github PK

View Code? Open in Web Editor NEW
70.0 7.0 14.0 1.33 MB

A very lightweight and fast speed PHP request router. 非常快速且轻量的请求匹配路由器。无依赖、简洁、自定义性强,查找匹配速度快

Home Page: https://inhere.github.io/php-sroute/

License: MIT License

PHP 99.93% Shell 0.07%
router route php-router dispatch php matchall routing web-router

php-sroute's Introduction

Hi Everyone 👋

inhere's github stats language


🚀💻 Technologies & Tools

Git GitHub IntelliJ PHP Java Go

My Organizations

Gookit Projects

ReadMe Card ReadMe Card
ReadMe Card ReadMe Card
ReadMe Card ReadMe Card

Contribuited Projects

ReadMe Card ReadMe Card

php-sroute's People

Contributors

dependabot[bot] avatar inhere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-sroute's Issues

https://www.demo.cn//index.php?m=ke

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

404 page not found 是什么问题

这是代码:

<?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 ,所有的类都加载了,这错误是怎么回事?

无法加载类?奇怪

atal error: Uncaught Error: Class 'Inhere\Route\Router' not found in J:\r\index.php:4 Stack trace: #0 {main} thrown in J:\r\index.php on line 4

index.php

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';
});

添加middleware 不生效

        // 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"
  }
}

如何指定controller路径呢?

<?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 Page Not Found

你好,我按照你的方法调用返回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()调用之后发现没有参数传入,我手动填了之后就起作用了,
新手不懂的地方请见谅

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.