Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Twig Constant Accessor Bundle Laravel Package

jdecool/twig-constant-accessor-bundle

Symfony bundle that integrates a Twig extension for reading PHP class constants and enum cases directly in templates. It exposes a dedicated accessor function so shared values can stay in PHP while remaining easy to use in Twig, without writing custom extensions.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Build vs. buy (and the answer is usually "neither"): Twig already ships a built-in constant('App\\Enum::VALUE') function, so the core capability this bundle wraps is available with zero dependencies. This package mainly adds namespace-prefix configuration (so templates can write constant('STATUS_ACTIVE') instead of a fully-qualified path) and a small DX layer. That makes the real decision "add a dependency vs. write ~50 lines," not "buy vs. build."
  • Single source of truth between PHP and templates: If product requirements include things like order statuses, plan tiers, feature-flag names, or permission strings that must render consistently in PHP and in views, exposing class constants to Twig removes magic strings from templates. That is a genuine correctness/quality argument — a typo becomes a template error rather than a silently wrong label.
  • Fitness for the actual stack: This is a Symfony bundle, not a Laravel package — the repository name and namespace confirm it. If your product is Laravel, this does not apply without TwigBridge, and the decision is effectively "no." Confirm the framework before it enters any roadmap.
  • Roadmap and maintenance posture: With 9 stars, 0 dependents, a release in May 2024, and the repository archived, the opportunity score (10.83/100) reflects the reality: there is no vendor to lean on. Any adoption decision is really a decision to own the code internally.
  • Migration/exit cost planning: Because the surface area is tiny and the behavior is well-understood, this is a low-risk "vendor it and forget it" candidate — a reasonable tactical choice for a legacy Symfony app with a frozen dependency policy, not a strategic one.

When to Consider This Package

Consider it (or, more realistically, copying the extension class into your codebase) when:

  • You are on Symfony with Twig, and templates are littered with fully-qualified constant strings that hurt readability or break when namespaces move.
  • You have a large volume of templates referencing domain constants and want a short, configured namespace-prefix ergonomics layer.
  • The app is in maintenance mode with a stable Symfony/Twig version pinned — i.e., the archived status costs you nothing because you aren't upgrading.

Look elsewhere — or just use the built-ins — when:

  • You are on Laravel (no Twig by default; Blade has no equivalent need) or on any non-Symfony PHP framework.
  • You need maintained dependencies with security response: archived means no patches for future Twig 4 / PHP 8.5+ breakage. The built-in constant() function has the same DX win minus the prefix sugar, and it's maintained by the Twig team.
  • Your constants are really user-facing copy or configuration — those belong in a settings/i18n layer, not const declarations, and neither this bundle nor Twig's built-in solves that properly.
  • You have enum-heavy domain models: prefer Twig's native enum support and constant() over a wrapper.
  • Your team's dependency policy requires active maintenance, SBOM tracking, or a named maintainer — this fails all three.

Recommended default: treat this as a reference implementation, not a dependency. Read it, reimplement the ~1 extension class internally, and keep your dependency count flat.

How to Pitch It (Stakeholders)

For executives: This is a small, low-risk developer-ergonomics utility — not a product capability. It lets templates reference PHP constants by short name instead of long class paths, which reduces typo-driven display bugs and makes views easier to read. The catch: it's a Symfony-only bundle that is archived and unmaintained, with negligible community adoption. We should not take a dependency on it. The honest recommendation is to not add it to the stack, and if a team genuinely wants the ergonomics, spend roughly a day replicating the behavior in-house so we own it. Cost of adoption is near zero; cost of depending on it is future upgrade friction, which we avoid entirely by building the small piece ourselves.

For engineering: Twig's built-in constant() already covers 90% of the value. The bundle's increment is configurable namespace prefixes so templates can write constant('STATUS_ACTIVE'). Repo is archived, last release 2024-05-02, 9 stars, 0 dependents — no upstream support and no compat guarantees past the Twig version it targets. Recommend: vendor the extension class (MIT licensed, attribution required), add a unit test around the prefix resolution, and pin your Twig major version. Do not add it to composer.json.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels