Download the PHP package eril/uri-mapper without Composer
On this page you can find all versions of the php package eril/uri-mapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package uri-mapper
PHP - URI Mapper
URI Mapper is a lightweight CLI tool that generates a named URI catalog from a filesystem structure.
It is designed to help developers reference important entry-point URIs in a stable, explicit, and refactor-friendly way — without acting as a router or imposing architectural decisions.
This tool does not handle HTTP dispatching, request matching, or middleware.
It only maps filesystem paths to named URIs and generates a small helper class for convenience.
Why URI Mapper?
In many projects, URIs are managed manually — and that is often the right choice.
However, some URIs are:
- referenced frequently,
- shared across the application,
- or expensive to refactor when paths change.
URI Mapper helps in these cases by providing:
- stable identifiers for key URIs,
- safe refactoring through aliases,
- and a small helper API to build paths consistently.
It is opt-in by design:
you decide how much or how little you want it to map.
Features
- Stable URI IDs via
@routeannotations -
Automatic aliases for backward compatibility
- Index-only mode for clean, folder-based mappings (
--index) - Optional
.phppreservation in generated URIs (--php) - Explicit URI composition via relative paths
- Zero runtime dependencies
- No routing, no dispatching, no framework coupling
Installation
Basic Usage
Run the mapper against a directory containing your route files:
This will generate a Uri.php helper class containing named URI constants.
Filesystem Mapping
Given the following structure:
The generated class will expose named URIs such as:
Named Routes (@route)
You can define a stable URI identifier using an annotation at the top of a PHP file:
ou
This decouples the URI name from the filesystem path.
If the path changes later, the identifier remains valid.
Aliases and Backward Compatibility
When a @route annotation is present, the automatically generated name becomes an alias.
Example:
Allows:
This makes refactoring safe and explicit.
Index-Only Mode (--index)
By default, all PHP files are considered.
To generate only folder-level URIs, use:
This produces a cleaner API focused on entry points:
Without generating leaf routes like Uri::adminUsers().
Preserving .php in URIs (--php)
By default, generated URIs do not include .php.
To preserve it:
Explicit URI Composition (Relative Paths)
The generated Uri helper allows composing URIs explicitly using relative paths.
This is especially useful when using --index and building links in templates.
Rule
If the first argument starts with
/, it is treated as a path relative to the base URI.
Examples
With parameters:
Query string:
This mechanism performs simple string substitution only. It does not define routes, validate parameters, or perform dispatching.
Output Modes
Dry Run
Generates the catalog without writing files.
JSON Export
Outputs the URI map as JSON instead of generating a class.
Generated Helper Class
The generated Uri class provides:
As well as request helpers:
Design Philosophy
URI Mapper is intentionally minimal.
- It does not replace routers.
- It does not enforce patterns.
- It does not hide behavior.
It exists solely to make important URIs explicit, stable, and easy to reference.
Use it where it helps — ignore it where it doesn’t.
License
MIT © Eril TS Carvalho