switon/router

Attribute-discovered routes, route tables, and literal and dynamic path matching for Switon Framework

Maintainers

Package info

github.com/switon-php/router

Documentation

pkg:composer/switon/router

Statistics

Installs: 23

Dependents: 5

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-06 13:43 UTC

This package is auto-updated.

Last update: 2026-06-07 03:57:09 UTC


README

CI PHP 8.3+

Switon's route matcher for literal and dynamic paths, attribute discovery, prefix-aware matching, and route resolution events.

Highlights

  • Attribute-based routing: controllers and actions declare routes in place with #[RequestMapping] and method mappings.
  • Prefix-aware discovery: controller prefixes can be derived from names or set explicitly.
  • Path mapping rules: '', relative, absolute, and array paths all map cleanly to routes.
  • View mappings: #[ViewGetMapping] and related attributes can add GET views beside write actions.
  • Fast route lookup: literal routes stay in hash lookups while dynamic ones compile to regex.
  • Match visibility: RouteNotFound and RouteParamsResolved expose misses and parameter resolution.

Installation

composer require switon/router

Quick Start

use Switon\Routing\Attribute\GetMapping;
use Switon\Routing\Attribute\RequestMapping;

#[RequestMapping('/user')]
class UserController
{
    #[GetMapping('{id}')]
    public function showAction(int $id): array
    {
        return ['id' => $id];
    }
}

Docs: https://docs.switon.dev/latest/router

License

MIT.