GithubHelp home page GithubHelp logo

splashsky / simplerouter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from steampixel/simplephprouter

3.0 3.0 1.0 88 KB

A very light, easy-to-use router for small PHP apps.

License: MIT License

PHP 100.00%
php php-router router simple url-parser

simplerouter's People

Contributors

beopuppy avatar immaax avatar mrjk990 avatar mzaini30 avatar splashsky avatar steampixel avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

lookingdown

simplerouter's Issues

Can't define an empty route ('')

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.

Add the ability to group routes to a subdomain

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.

bug in run() with basepath != '/' ?

(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

Route parameter constraints can overlap

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.

Allow RegEx constraints for new parameters

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.

Investigate potential for a "conditional" on routes

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.

404 when callable is empty

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!

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.