Skip to content

feat: add the EnvironmentDetector utility class and environment service#10130

Merged
paulbalandan merged 1 commit intocodeigniter4:4.8from
paulbalandan:environment-detector
Apr 26, 2026
Merged

feat: add the EnvironmentDetector utility class and environment service#10130
paulbalandan merged 1 commit intocodeigniter4:4.8from
paulbalandan:environment-detector

Conversation

@paulbalandan
Copy link
Copy Markdown
Member

Description
This PR adds the EnvironmentDetector utility class as a simple mockable wrapper to accessing the ENVIRONMENT constant, allowing us to test previously unreachable code branches dependent on the current environment.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@github-actions github-actions Bot added the 4.8 PRs that target the `4.8` branch. label Apr 23, 2026
Copy link
Copy Markdown
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good change.

I added some suggestions to the phpdocs / user guide.

Comment thread system/Config/Services.php
Comment thread system/EnvironmentDetector.php
Comment thread user_guide_src/source/general/environments.rst
@paulbalandan paulbalandan force-pushed the environment-detector branch from 7231481 to 86fe9de Compare April 23, 2026 15:27
Comment thread system/EnvironmentDetector.php
Comment thread user_guide_src/source/general/environments.rst Outdated
Comment thread system/Config/Services.php Outdated
@paulbalandan paulbalandan force-pushed the environment-detector branch from 86fe9de to 0549469 Compare April 23, 2026 19:33
@paulbalandan paulbalandan changed the title feat: add the EnvironmentDetector utility class and environmentdetector service feat: add the EnvironmentDetector utility class and envdetector service Apr 23, 2026
Copy link
Copy Markdown
Contributor

@neznaika0 neznaika0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread system/Database/MigrationRunner.php Outdated
@paulbalandan paulbalandan force-pushed the environment-detector branch from 0549469 to 8315469 Compare April 24, 2026 07:50
@michalsn
Copy link
Copy Markdown
Member

envdetector is shorter, but it reads like ".env detector" or "environment variables detector", which is a different concept in this codebase.

Why not just use environment? It's the most natural read: service('environment')->isProduction().

It's also aligned with the code we used to write: ENVIRONMENT === 'production'.

@neznaika0
Copy link
Copy Markdown
Contributor

I have already said my opinion - for the environment, this can already be attributed to the DotEnv loader. Since the comparison with a constant looks clear, and the service is associated with all the features of $_ENV.

The last word belongs to the members, I have less importance here.

@michalsn
Copy link
Copy Markdown
Member

In this context, "environment" means the current CI runtime mode (development, production, testing), not DotEnv or general $_ENV handling.

DotEnv is about loading environment variables, while this service is only about checking the current application environment in a mockable way. Those are related concepts, but not the same responsibility.

@neznaika0
Copy link
Copy Markdown
Contributor

@michalsn thanks for the clarification. I know this, and I can always see what the code is doing in the system.

It's more about the other participants. You can see the questions in the Issue/Forum ‐ someone mistakenly perceives the specifics of the framework or expects precise actions in the documentation (although everything looks clear to us).

@michalsn
Copy link
Copy Markdown
Member

I see your point, but I don't find environment misleading. To me, envdetector actually sounds more like something related to .env detection.

@paulbalandan paulbalandan force-pushed the environment-detector branch from 8315469 to 76586d4 Compare April 25, 2026 11:42
@paulbalandan paulbalandan changed the title feat: add the EnvironmentDetector utility class and envdetector service feat: add the EnvironmentDetector utility class and environment service Apr 25, 2026
Copy link
Copy Markdown
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good.

@paulbalandan paulbalandan merged commit d0bb6b0 into codeigniter4:4.8 Apr 26, 2026
56 checks passed
@paulbalandan paulbalandan deleted the environment-detector branch April 26, 2026 04:57
@paulbalandan
Copy link
Copy Markdown
Member Author

Thanks all for the reviews!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants