Skip to content

Commit 7330e3d

Browse files
fix: remove global env() helper from package
1 parent 4974192 commit 7330e3d

File tree

6 files changed

+44
-32
lines changed

6 files changed

+44
-32
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@ All notable changes to this package will be documented in this file.
44

55
## [Unreleased]
66

7+
## [2.0.1] - 2025-10-05
8+
9+
### Fixed
10+
11+
- Removed global `env()` helper from the package to keep framework-level responsibility in `codemonster-ru/annabel`.
12+
- The package now exposes only the static API through `Codemonster\Env\Env`.
13+
14+
### Docs
15+
16+
- Updated `README.md` to reflect the removal of the global helper.
17+
Examples now use `Env::get()` instead of `env()`.
18+
19+
### Tests
20+
21+
- Updated all tests to use `Env::get()` instead of the removed global `env()` helper.
22+
23+
### Internal
24+
25+
- Verified autoload configuration in `composer.json` (removed helper file registration).
26+
- No API-breaking changes; patch-level release only.
27+
728
## [2.0.0] - 2025-09-28
829

930
### Changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ composer require codemonster-ru/env
1717

1818
## 🚀 Usage
1919

20-
Create a .env file in the root of your project:
20+
Create a `.env` file in the root of your project:
2121

2222
```dotenv
2323
APP_NAME=MyApp
@@ -37,15 +37,17 @@ require __DIR__ . '/vendor/autoload.php';
3737

3838
use Codemonster\Env\Env;
3939

40+
// Load environment variables from .env
4041
Env::load(__DIR__ . '/.env');
4142

42-
echo env('APP_NAME'); // "MyApp"
43-
var_dump(env('FEATURE_ENABLED')); // true (bool)
44-
var_dump(env('FEATURE_DISABLED')); // false (bool)
45-
var_dump(env('OPTIONAL_VALUE')); // null
46-
var_dump(env('EMPTY_VALUE')); // ""
47-
echo env('SSR_URL'); // http://localhost:3000
48-
echo env('NOT_DEFINED', 'default'); // "default"
43+
// Access values via Env::get()
44+
echo Env::get('APP_NAME'); // "MyApp"
45+
var_dump(Env::get('FEATURE_ENABLED')); // true (bool)
46+
var_dump(Env::get('FEATURE_DISABLED')); // false (bool)
47+
var_dump(Env::get('OPTIONAL_VALUE')); // null
48+
var_dump(Env::get('EMPTY_VALUE')); // ""
49+
echo Env::get('SSR_URL'); // http://localhost:3000
50+
echo Env::get('NOT_DEFINED', 'default'); // "default"
4951
```
5052

5153
## ✨ Features

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"type": "library",
55
"license": "MIT",
66
"homepage": "https://github.com/codemonster-ru/env",
7+
"readme": "README.md",
78
"authors": [
89
{
910
"name": "Kirill Kolesnikov",
@@ -15,10 +16,7 @@
1516
"autoload": {
1617
"psr-4": {
1718
"Codemonster\\Env\\": "src/"
18-
},
19-
"files": [
20-
"src/helpers.php"
21-
]
19+
}
2220
},
2321
"require": {
2422
"php": ">=8.2"

src/Env.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static function load(string $path): void
2828
if (!array_key_exists($name, $_ENV) && !array_key_exists($name, $_SERVER)) {
2929
$_ENV[$name] = $value;
3030
$_SERVER[$name] = $value;
31+
3132
putenv("$name=$value");
3233
}
3334
}

src/helpers.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/EnvTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,39 @@ protected function setUp(): void
2626

2727
public function testEnvLoadsString(): void
2828
{
29-
$this->assertSame('MyApp', env('APP_NAME'));
29+
$this->assertSame('MyApp', Env::get('APP_NAME'));
3030
}
3131

3232
public function testEnvCastsTrueFalse(): void
3333
{
34-
$this->assertTrue(env('FEATURE_ENABLED'));
35-
$this->assertFalse(env('FEATURE_DISABLED'));
34+
$this->assertTrue(Env::get('FEATURE_ENABLED'));
35+
$this->assertFalse(Env::get('FEATURE_DISABLED'));
3636
}
3737

3838
public function testEnvCastsNull(): void
3939
{
40-
$this->assertNull(env('OPTIONAL_VALUE'));
40+
$this->assertNull(Env::get('OPTIONAL_VALUE'));
4141
}
4242

4343
public function testEnvCastsEmpty(): void
4444
{
45-
$this->assertSame('', env('EMPTY_VALUE'));
45+
$this->assertSame('', Env::get('EMPTY_VALUE'));
4646
}
4747

4848
public function testEnvRemovesQuotes(): void
4949
{
50-
$this->assertSame('http://localhost:3000', env('SSR_URL'));
50+
$this->assertSame('http://localhost:3000', Env::get('SSR_URL'));
5151
}
5252

5353
public function testEnvHandlesSingleAndDoubleQuotes(): void
5454
{
55-
$this->assertSame('Hello Single', env('QUOTED_SINGLE'));
56-
$this->assertSame('Hello Double', env('QUOTED_DOUBLE'));
55+
$this->assertSame('Hello Single', Env::get('QUOTED_SINGLE'));
56+
$this->assertSame('Hello Double', Env::get('QUOTED_DOUBLE'));
5757
}
5858

5959
public function testEnvReturnsDefaultIfNotSet(): void
6060
{
61-
$this->assertSame('default', env('NOT_DEFINED', 'default'));
61+
$this->assertSame('default', Env::get('NOT_DEFINED', 'default'));
6262
}
6363

6464
public function testEnvDoesNotOverrideExisting(): void
@@ -67,6 +67,6 @@ public function testEnvDoesNotOverrideExisting(): void
6767

6868
Env::load(__DIR__ . '/.env.example');
6969

70-
$this->assertSame('ManualApp', env('APP_NAME'));
70+
$this->assertSame('ManualApp', Env::get('APP_NAME'));
7171
}
7272
}

0 commit comments

Comments
 (0)