承接 eril/uri-mapper 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

eril/uri-mapper

Composer 安装命令:

composer require eril/uri-mapper

包简介

A lightweight CLI tool to generate a named URI catalog from the filesystem, with stable IDs, aliases, and optional recursive index mapping.

README 文档

README

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 @route annotations

  • Automatic aliases for backward compatibility

  • Index-only mode for clean, folder-based mappings (--index)

  • Optional .php preservation in generated URIs (--php)

  • Explicit URI composition via relative paths

  • Zero runtime dependencies

  • No routing, no dispatching, no framework coupling

Installation

composer require eril/uri-mapper

Basic Usage

Run the mapper against a directory containing your route files:

# vendor/bin/uri-mapper <path> [options]
vendor/bin/uri-mapper ./routes

This will generate a Uri.php helper class containing named URI constants.

Filesystem Mapping

Given the following structure:

routes/
├── index.php
├── services/
│   └── index.php
├── admin/
│   ├── index.php
│   └── users.php

The generated class will expose named URIs such as:

Uri::home();      // /
Uri::services();  // /services/
Uri::admin();     // /admin/

Named Routes (@route)

You can define a stable URI identifier using an annotation at the top of a PHP file:

<?php
// @route dashboard

?>

ou

<!-- @route dashboard  --->
<?php 

?>

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:

/login/index.php   // @route signin

Allows:

Uri::signin(); // preferred
Uri::login();  // alias, still works

This makes refactoring safe and explicit.

Index-Only Mode (--index)

By default, all PHP files are considered.

To generate only folder-level URIs, use:

vendor/bin/uri-mapper ./routes --index

This produces a cleaner API focused on entry points:

Uri::home('services');   // /services/
Uri::admin('users');    // /admin/users/

Without generating leaf routes like Uri::adminUsers().

Preserving .php in URIs (--php)

By default, generated URIs do not include .php.

To preserve it:

vendor/bin/uri-mapper ./routes --php

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

Uri::admin('/users');
// /admin/users

With parameters:

Uri::admin('/users/{id}', ['id' => 1]);
// /admin/users/1

Query string:

Uri::admin('/users', ['page' => 2]);
// /admin/users?page=2

This mechanism performs simple string substitution only. It does not define routes, validate parameters, or perform dispatching.

Output Modes

Dry Run

vendor/bin/uri-mapper ./routes --dry-run

Generates the catalog without writing files.

JSON Export

vendor/bin/uri-mapper ./routes --json

Outputs the URI map as JSON instead of generating a class.

Generated Helper Class

The generated Uri class provides:

Uri::home();
Uri::admin('users');
Uri::services(['page' => 2]);

As well as request helpers:

Uri::uri();   // current request URI
Uri::url();   // full URL
Uri::param(); // GET parameters

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

eril/uri-mapper 适用场景与选型建议

eril/uri-mapper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「routing」 「php」 「filesystem」 「cli」 「uri」 「mapper」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 eril/uri-mapper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 eril/uri-mapper 我们能提供哪些服务?
定制开发 / 二次开发

基于 eril/uri-mapper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 36
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-23