splashsky / simplerouter Goto Github PK
View Code? Open in Web Editor NEWThis project forked from steampixel/simplephprouter
A very light, easy-to-use router for small PHP apps.
License: MIT License
This project forked from steampixel/simplephprouter
A very light, easy-to-use router for small PHP apps.
License: MIT License
As of release v2.2.0, you can't define an empty route ''
and expect it to work properly. It also allows you to define two "base" routes, ''
and '/'
. In order to make the behavior of the base route more consistent and easier to predict, we should implement a trimming method that ensures there's always a beginning slash for both routes and the requested URI.
I'd like to add the ability to "group" routes to a subdomain (basically a different $basePath
) without requiring another entrypoint/router to do so. This would effectively alleviate the issue in steampixel#43 and bring us closer to a Laravel-like experience.
(Translated by Google)
Hello
I am testing a version modified by me, of ROUTER.PHP
and when I use for example:
Router::add('/', function () {
echo 'Welcome to v3';
});
Router: run('/v3');
I needed to modify this line in the RUN method
if ($basePath != '/') {
$route['route'] = self::trimRoute($basePath. $route['route']);
}
Otherwise the path "/" always returned 404
This only happened with the '/' path, the others always worked fine.
Maybe it is really necessary to change it in this repository
Unfortunately ran into a bug where route parameter constraints that apply to the same route parameter name overlap, causing 404s if the routes with different constraints aren't found first. This fix probably involves storing constraints in an array tied to the route itself as a key.
When using the same route (/login
) with two methods (GET, POST), the router will 405 when using the earlier method.
Router::get('/login'); // 405
Router::post('/login'); // works
The next big priority item is to accept a RegEx constraint for router parameters, via a method that can be chained onto a route method. This would look something like this:
// Single parameter
Router::get('/hello/{name}', function ($n) {
return "Hello, $n!";
})->where('name', '[A-Za-z0-9]+');
// Multi parameter
Router::get('/hello/{name}/age/{num}', function ($n, $a) {
return "Hello, $a yo named $n!";
})->where(['name' => '[A-Za-z0-9]+', 'num' => '[0-9]+']);
This ensures the user can have the level of control they want, while keeping it concise and clean.
While I don't want to complicate the router more than necessary, having a concise way to add route "conditions" (e.g. a user being logged in) in the router might be handy.
I don't want to escalate to the level of Laravel's powerful Middleware, but a simple ->if(Auth::loggedIn())
type of method you can chain onto the Router::get()
method is worth investigating.
Would also address steampixel#44.
When you provide an empty callable, such as
$router->post('/auth/register', function() {
});
the router will return the 404 response rather than execute the callable. This is undesirable!
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.