Skip to content

Add env() helper for cross-scope environment variable access#1985

Merged
bpamiri merged 1 commit intodevelopfrom
peter/1783-env-helper
Mar 16, 2026
Merged

Add env() helper for cross-scope environment variable access#1985
bpamiri merged 1 commit intodevelopfrom
peter/1783-env-helper

Conversation

@bpamiri
Copy link
Collaborator

@bpamiri bpamiri commented Mar 16, 2026

Summary

  • Copies this.envapplication.env in onApplicationStart() so .env values are available outside Application.cfc
  • Adds env(name, default) helper to Global.cfc — callable from controllers, models, and views
  • Lookup order: application.env (from .env files) → server.system.environment (system env vars) → default value

Access patterns after this change

Context How to access
config/app.cfm this.env.VAR (unchanged — included inline in Application.cfc)
config/settings.cfm application.env.VAR (new)
Controllers/models/views env("VAR") or env("VAR", "fallback") (new)

Test plan

  • env() returns value from application.env when present
  • env() returns custom default when key not found
  • env() falls back to server.system.environment (e.g., PATH)
  • env() prefers application.env over system env
  • application.env is populated at app start

Closes #1783

🤖 Generated with Claude Code

this.env is only accessible within Application.cfc and its includes.
This copies this.env into application.env at app start and adds an
env(name, default) helper to Global.cfc so controllers, models, and
views can read .env values. Falls back to server.system.environment
for cross-engine compatibility.

Closes #1783

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

Wheels Test Matrix

Engine MySQL PostgreSQL SQL Server H2 Oracle SQLite
lucee5
lucee6
lucee7
adobe2018 -- --
adobe2021 --
adobe2023 --
adobe2025 --
boxlang --

Results for commit 15bdaeb.

@github-actions
Copy link
Contributor

Wheels Test Results

    42 files  ±0   3 906 suites  ±0   25m 22s ⏱️ -28s
79 512 tests ±0  79 124 ✅ ±0  388 💤 ±0  0 ❌ ±0 
82 158 runs  ±0  81 770 ✅ ±0  388 💤 ±0  0 ❌ ±0 

Results for commit 1e3d61a. ± Comparison against base commit 0e18367.

@bpamiri bpamiri merged commit e57ecf8 into develop Mar 16, 2026
12 checks passed
@bpamiri bpamiri deleted the peter/1783-env-helper branch March 16, 2026 04:00
@bpamiri bpamiri added this to the v3.1 milestone Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate cross-engine .env file loading for Lucee, BoxLang, and Adobe ColdFusion

1 participant