PHPackages                             phpgt/routing - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. phpgt/routing

ActiveLibrary[Templating &amp; Views](/categories/templating)

phpgt/routing
=============

Routes HTTP requests to your code.

v1.1.8(4w ago)05.1k↑289.5%[1 issues](https://github.com/PhpGt/Routing/issues)[2 PRs](https://github.com/PhpGt/Routing/pulls)2MITPHPPHP &gt;=8.1CI passing

Since May 25Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/PhpGt/Routing)[ Packagist](https://packagist.org/packages/phpgt/routing)[ GitHub Sponsors](https://github.com/sponsors/phpgt)[ RSS](/packages/phpgt-routing/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (10)Dependencies (30)Versions (34)Used By (2)

Routes HTTP requests to logic and view files.
=============================================

[](#routes-http-requests-to-logic-and-view-files)

As HTTP requests are received by an application, the appropriate logic methods need to be called, along with certain files being loaded to construct the correct view for the request. This is done by taking the HTTP request and *routing* it to the matching areas of the application source code.

This repository breaks down the concept of routing into three areas of responsibility:

1. Matching an HTTP request to an appropriate callback function.
2. Creating an Assembly of logic and view files that match the request.
3. Processing the Assemblies, in order to create the correct HTTP response.

When referring to Requests within this repository, we are always referring to a [PSR-7 HTTP Message](https://www.php-fig.org/psr/psr-7/).

---

[ ![Build status](https://camo.githubusercontent.com/d38a5ff3574baf52b1105227ed8c1cd4dd9e41bd1dcb916d0d415c5fbc431900/68747470733a2f2f62616467652e7374617475732e7068702e67742f726f7574696e672d6275696c642e737667)](https://github.com/PhpGt/Routing/actions)[ ![Code quality](https://camo.githubusercontent.com/3aca0b674a7029485ae77140b67c912d9fdc1663ca27a5a29628f24aa3af9088/68747470733a2f2f62616467652e7374617475732e7068702e67742f726f7574696e672d7175616c6974792e737667)](https://app.codacy.com/gh/PhpGt/Routing)[ ![Code coverage](https://camo.githubusercontent.com/20b7b35abfe6308dbda47883419680a650edf5d88a4e9611e5f5b0fd782b3ede/68747470733a2f2f62616467652e7374617475732e7068702e67742f726f7574696e672d636f7665726167652e737667)](https://app.codecov.io/gh/PhpGt/Routing)[ ![Current version](https://camo.githubusercontent.com/d8c663a4288fbb8b7479b5ae75d3e28d9bdd9c1ba7bc7d96a7ef24ce38a0021e/68747470733a2f2f62616467652e7374617475732e7068702e67742f726f7574696e672d76657273696f6e2e737667)](https://packagist.org/packages/PhpGt/Routing)[ ![PHP.G/Routing documentation](https://camo.githubusercontent.com/10d66e819701be5334d087dc64c3dfb62ffa295869091f738e94b89c11d39dee/68747470733a2f2f62616467652e7374617475732e7068702e67742f726f7574696e672d646f63732e737667)](http://www.php.gt/routing)Planning
--------

[](#planning)

Main flow:

- Your application can have a `router.php` in project root, but is completely optional due to `router.default.php` being provided by WebEngine. You can use the router.php file to add complicated rules that define which source files are used to build up the response, rather than always being limited to using path-based rules, as is currently the case with WebEngine.
- The name of the application's router is defined in config by `app_router_path` key.
- The application router defines a class called `Router` in the application's root namespace, which extends `GT\Routing\AbstractRouter`.
- BaseRouter's `go()` method is called, supplying a PSR-7 `RequestInterface` which will call functions of the application's router.
- The application router can have any number of functions. They are made "routable" by adding an Attribute that extends `Route`. Available Attributes include `Get`, `Post` (and other HTTP verbs) or `Any` to match on all verbs.
- The simplest routable function has the Any attribute with no parameters (`#[Any()]`), which will be executed for every request.
- Available Attribute parameters include: `name` to provide the route a name for future reference, `accept` to provide a Content-type to match the Request's `Accept` header with, `path` to define a matching path (with pattern matching), `function` to define the function to call.
- Only the functions that have Attributes that match the incoming request will be executed.
- It's the job of the application's routable functions to add appropriate view and logic files to the Router's `Assembly` objects. The framework (WebEngine in my case) will then use the Assembly objects to build up the appropriate `View` and execute the appropriate `Logic` objects in the correct order.

TODO List:
----------

[](#todo-list)

- Perform content negotiation when there are multiple matches. For example: an API route might explicitly accept "application/xml" but the default accept header of web browsers also sends this for page requests, but it gives it a q=0.9 - as long as there is a route with text/html or application/xhtml+xml with a higher q value, it should be preferred.
- Take a RequestInterface and a project directory, and construct the appropriate Assembly objects - matching the URL path to directory paths, extracting dynamic paths where appropriate.

Proudly sponsored by
====================

[](#proudly-sponsored-by)

[JetBrains Open Source sponsorship program](https://www.jetbrains.com/community/opensource/)

[![JetBrains logo.](https://camo.githubusercontent.com/b5639e7738c6dfae9fe3f3e20175570b7376ce2577a772e09c25c2d4f14bf86e/68747470733a2f2f7265736f75726365732e6a6574627261696e732e636f6d2f73746f726167652f70726f64756374732f636f6d70616e792f6272616e642f6c6f676f732f6a6574627261696e732e737667)](https://www.jetbrains.com/community/opensource/)

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance94

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 87.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~116 days

Recently: every ~65 days

Total

17

Last Release

29d ago

Major Versions

v0.1.0 → v1.0.02021-08-31

PHP version history (2 changes)v0.0.1PHP &gt;=8.0

v1.1.3PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e42344b91ce4b91ab57875969f67a0a6a48de570a08bc65d673b06b72fd3a3f?d=identicon)[g105b](/maintainers/g105b)

---

Top Contributors

[![g105b](https://avatars.githubusercontent.com/u/358014?v=4)](https://github.com/g105b "g105b (27 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")

---

Tags

content-negotiationhttphttp-apihttp-requesthttp-responseno-airequesturlurirouterviewrouteredirectlogicassembly

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpgt-routing/health.svg)

```
[![Health](https://phpackages.com/badges/phpgt-routing/health.svg)](https://phpackages.com/packages/phpgt-routing)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B4.3k](/packages/guzzlehttp-psr7)[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k555.0M2.8k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k832.6k51](/packages/neuron-core-neuron-ai)[moonshine/moonshine

Laravel administration panel

1.3k268.2k87](/packages/moonshine-moonshine)[getgrav/grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS

15.6k88.1k1](/packages/getgrav-grav)[phpgt/webengine

Minimalistic, ergonomic PHP toolkit.

2722.4k](/packages/phpgt-webengine)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
