Download the PHP package cr0w/phorq without Composer
On this page you can find all versions of the php package cr0w/phorq. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package phorq
⎇ phorq
File-based routing for PHP
Your directory structure is your URL structure. Dynamic params, catch-alls, middleware, and modules all work out of the box.
Install
Quick start
Front controller
Pass an optional context as the first argument to thread shared state through middleware and route files:
$ctx can be anything — a plain object, an array, a service container. phorq doesn't inspect it.
Routing conventions
| File / directory | Matches |
|---|---|
index.php |
Directory root |
about.php |
/about |
[id].php |
Dynamic segment /42, $id available |
[id]/settings/index.php |
/42/settings, $id available |
[...rest].php |
Catch-all, $rest is array of segments |
[[...rest]].php |
Optional catch-all file |
[[...rest]]/index.php |
Optional catch-all directory |
Method branching
Handle different HTTP methods inside the route file using $req:
Catch-all routes
A catch-all ([...rest].php or [...rest]/index.php) captures one or more remaining path segments into an array variable. It only matches when at least one segment is present — /docs alone will not match docs/[...rest].php.
An optional catch-all ([[...rest]].php or [[...rest]]/index.php) also matches the bare directory. /pages matches with $rest = [], and /pages/a/b matches with $rest = ['a', 'b'].
Precedence
- Exact static match (
about.php) - Dynamic param (
[id].php) - Catch-all (
[...rest].php)
Static directories are walked before dynamic or catch-all directories.
Modules
Each subdirectory of the modules folder is a module. A module can have:
config.php— returns['mount' => 'prefix']to set the URL prefixmiddleware.php— returns a callable (see below)routes/— file-based routes
The core module is special:
- Routes under
core/routes/serve as the fallback when no other module matches. - Core middleware runs before module-specific middleware on every request.
- Module mounts always win. If a module is mounted at
/blog, a core route atcore/routes/blog/is unreachable.
Route files
Every route file receives these variables:
$req is a phorq\Request with typed accessors:
Route files can return any value. The front controller decides what to do with it:
Middleware
Trailing parameters you don't need can be omitted:
Middleware stacking order: core → module → handler.
Caching
Pass a cache file path to Router::create() and the route map is written once, then loaded from cache on subsequent requests. Delete the file to rebuild.
Omit the second argument (or pass null) to disable caching during development.
Testing
Running the example
Then visit:
License
MIT