finds.dev← search

// the find

skipperbent/simple-php-router

★ 671 · PHP · updated Nov 2024

Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.

A standalone PHP router, installed with Composer as pecee/simple-router, that borrows Laravel's routing syntax: closure and controller callbacks, named routes, route groups with middleware and namespaces, and a pluggable CSRF verifier. It suits small PHP projects that want routing and input handling without a full framework.

- The extension points are interfaces (IMiddleware, IExceptionHandler, ITokenProvider, IClassLoader, IRouterBootManager), so the CSRF token store or class loader can be replaced, for example with php-di, without forking the router.

- Exception handlers merge through nested groups by default, and setting mergeExceptionHandlers to false lets a group opt out. The README documents this with a worked example, which is a deliberate design choice.

- The test directory covers middleware, groups, partial groups, resources, controllers, rewrites, URL generation and CSRF, and the repo includes a PHPStan config and a CI workflow. That is more verification than most small routers ship with.

- Trailing-slash handling for the last parameter is opt-in and documented, with the WebDAV file-versus-folder case as the motivating example. The Apache, Nginx and IIS rewrite configs are written out in full.

- The last push was November 2024, and the README still lists PHP 7.1 as the minimum, a version that has been end-of-life for years. Nothing in the README says it is tested on current PHP, so check that yourself before adopting it.

- The goal is stated as 'more or less 100% compatible' with Laravel's routing docs, but there is no list of where it differs. Anyone moving code over from Laravel will find the gaps by testing.

- Partial groups have a documented trap: url() cannot resolve routes inside a partial group until its prefix has matched. Code that builds links to plugin routes before the plugin is hit will fail silently.

- The default parameter pattern only accepts ASCII word characters and hyphens. Accented or non-Latin slugs need a defaultParameterRegex on every affected route or group, which is easy to miss in one place.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →