Skip to content

Commit 86fe9de

Browse files
committed
address review suggestions
1 parent 9783bc2 commit 86fe9de

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

system/Config/Services.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,11 @@ public static function encrypter(?EncryptionConfig $config = null, $getShared =
264264
* Provides a simple way to determine the current environment
265265
* of the application.
266266
*
267-
* @return EnvironmentDetector
267+
* Primarily intended for testing environment-specific branches by
268+
* mocking this service. Mocking it does not modify the `ENVIRONMENT`
269+
* constant. It only affects code paths that resolve and use this service.
268270
*/
269-
public static function environmentdetector(?string $environment = null, bool $getShared = true)
271+
public static function environmentdetector(?string $environment = null, bool $getShared = true): EnvironmentDetector
270272
{
271273
if ($getShared) {
272274
return static::getSharedInstance('environmentdetector', $environment);

system/EnvironmentDetector.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
/**
1919
* Provides a simple way to determine the current environment of the application.
2020
*
21+
* Primarily intended as a mockable seam for testing environment-specific code
22+
* paths that resolve this class via the `environmentdetector` service.
23+
*
24+
* It does not redefine the `ENVIRONMENT` constant. It affects only code paths
25+
* that resolve and use this class, while code that still reads `ENVIRONMENT`
26+
* directly keeps its current behavior.
27+
*
2128
* For custom environment names beyond the built-in production/development/testing,
2229
* use {@see self::is()}.
2330
*

user_guide_src/source/general/environments.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ constant.
161161

162162
.. literalinclude:: environments/001.php
163163

164+
.. note::
165+
166+
The ``environmentdetector`` service is primarily intended for testing
167+
environment-specific code paths. Mocking it only affects code that resolves
168+
and uses the service itself. It does not modify the ``ENVIRONMENT`` constant.
169+
Code that still reads ``ENVIRONMENT`` directly keeps its current behavior.
170+
164171
Passing a value to the constructor overrides the detected environment; passing
165172
``null`` (the default) falls back to the ``ENVIRONMENT`` constant. An empty or
166173
whitespace-only string throws ``CodeIgniter\Exceptions\InvalidArgumentException``.

0 commit comments

Comments
 (0)