gdbots/uri-template
A PHP implementation of URI templates (RFC 6570) for expanding and matching parameterized URI patterns. Build and parse templates with simple or complex expressions to generate links, API paths, and identifiers cleanly.
{/tenant}/projects{?page,limit}) instead of hardcoded strings. This directly informs whether to generate first-party SDKs from an OpenAPI spec or hand-maintain client URL builders — and whether the OpenAPI contract or the runtime code is the source of truth.sprintf conventions — small effort, measurable reduction in support tickets.Consider it when:
{+var}, {#frag}, {?q}, {/path*}) — and the alternative is hand-rolling the grammar.UrlTemplateExpander interface so it is swappable.Look elsewhere (or build) when:
route() and url(), or str_replace/sprintf, already cover {id}-style interpolation; adding a package here is unjustified complexity.league/uri, which is maintained and more widely adopted.guzzlehttp/uri-template is actively maintained, widely depended upon, and typically present transitively. Starting there carries strictly less risk for roughly the same feature set.Adoption gate: require a half-day spike covering the top 10 real templates, plus a written fallback plan (fork plus internal tests, or a swap to a maintained alternative) before any production dependency.
To executives: This is a small, standards-based utility — an implementation of RFC 6570, the IETF URI template standard — plus a starter catalog of common templates. It addresses a recurring, low-glamour source of defects: URLs assembled by hand in different services, which break integrations, deep links, and partner callbacks. The license is permissive (Apache-2.0, with a patent grant), the surface area is tiny, and the standard is stable, so technical risk is contained. The real risk is stewardship: the project is effectively unmaintained — no release since 2021, no community, no dependents. My recommendation is a time-boxed pilot, not broad adoption: adopt the code by vendoring it under our own tests and interface, prove it against our actual API contracts, and keep a one-day exit path to a maintained alternative. Upside is consistency across API clients and fewer broken-link incidents; downside is bounded to a few engineer-days.
To engineering: The package gives spec-compliant expansion (levels 1–4) plus a template catalog — roughly a few days of careful work to replicate correctly, since percent-encoding and reserved-character handling are easy to get subtly wrong. The trade is simple: take the code, not the dependency. Vendor or fork it, pin the version, wrap it behind a narrow UrlTemplateExpander port bound in a service provider, and add a conformance suite covering our real templates (multi-tenant paths, query expansion, asset/CDN URLs). Benchmark it if it lands in a per-request path, and validate expanded output where variables derive from user input and the URL feeds a redirect or outbound call. If we need URI parsing, normalization, or PSR-7 interop, pair it with league/uri rather than expanding scope. Decision requested: approve a half-day spike and a vendored adoption behind an interface — or defer, if the only real need is internal route generation.
How can I help you explore Laravel packages today?