Skip to content

Commit 9ee9d01

Browse files
authored
Add getVersion method to the Environment class
1 parent 7c7411a commit 9ee9d01

File tree

6 files changed

+32
-18
lines changed

6 files changed

+32
-18
lines changed

.github/ISSUE_TEMPLATE/1_Bug_report.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ labels: Bug
1414

1515
### Additional Info
1616

17-
| Q | A
18-
|------------------| ---
19-
| Package Version | x.y.z <!-- Please set the package version -->
20-
| PHP version | x.y.z <!-- Please set the PHP version -->
21-
| Operating system | Linux <!-- Please set your OS -->
17+
| Q | A |
18+
|------------------|-----------------------------------------------|
19+
| Package Version | x.y.z <!-- Please set the package version --> |
20+
| PHP version | x.y.z <!-- Please set the PHP version --> |
21+
| Operating system | Linux <!-- Please set your OS --> |
2222

2323
<!-- Optional: any other context about the problem: log messages, screenshots, etc. -->

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
| Q | A
2-
| ------------- | ---
3-
| Bugfix? | ✔️/❌
4-
| Breaks BC? | ✔️/❌ <!-- please update "xxx Impact Changes" section in CHANGELOG.md file -->
5-
| New feature? | ✔️/❌ <!-- please update "Other Features" section in CHANGELOG.md file -->
6-
| Issues | #... <!-- prefix each issue number with "#" symbol, no need to create an issue if none exist, explain below instead -->
7-
| Docs PR | spiral/docs#... <!-- prefix each issue number with "spiral/docs#", required only for new features -->
1+
| Q | A |
2+
|--------------|-------------------------------------------------------------------------------------------------------------------------|
3+
| Bugfix? | ✔️/❌ |
4+
| Breaks BC? | ✔️/❌ <!-- please update "xxx Impact Changes" section in CHANGELOG.md file --> |
5+
| New feature? | ✔️/❌ <!-- please update "Other Features" section in CHANGELOG.md file --> |
6+
| Issues | #... <!-- prefix each issue number with "#" symbol, no need to create an issue if none exist, explain below instead --> |
7+
| Docs PR | spiral/docs#... <!-- prefix each issue number with "spiral/docs#", required only for new features --> |
88

99
<!-- Please, replace this notice by a short description of your feature/bugfix.
1010
This will help people understand your PR and can be used as a start for the documentation. -->

src/Environment.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
/**
1010
* @psalm-import-type ModeType from Mode
1111
* @psalm-type EnvironmentVariables = array{
12-
* RR_MODE?: ModeType|string,
13-
* RR_RELAY?: string,
14-
* RR_RPC?: string,
12+
* RR_MODE?: ModeType|string,
13+
* RR_RELAY?: string,
14+
* RR_RPC?: string,
15+
* RR_VERSION?: string,
1516
* }|array<string, string>
1617
* @see Mode
1718
*/
@@ -27,7 +28,7 @@ public function __construct(
2728

2829
public function getMode(): string
2930
{
30-
return $this->get('RR_MODE', '');
31+
return $this->get('RR_MODE');
3132
}
3233

3334
public function getRelayAddress(): string
@@ -40,6 +41,11 @@ public function getRPCAddress(): string
4041
return $this->get('RR_RPC', 'tcp://127.0.0.1:6001');
4142
}
4243

44+
public function getVersion(): string
45+
{
46+
return $this->get('RR_VERSION');
47+
}
48+
4349
/**
4450
* @template TDefault of string
4551
*

src/EnvironmentInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*
1313
* @psalm-import-type ModeType from Mode
1414
* @see Mode
15+
* @method string getVersion()
1516
*/
1617
interface EnvironmentInterface
1718
{

src/Worker.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,10 @@ public static function createFromEnvironment(
276276
);
277277
}
278278

279-
private function sendProcessId(): static
279+
private function sendProcessId(): void
280280
{
281281
$frame = new Frame($this->encode(['pid' => \getmypid()]), [], Frame::CONTROL);
282282
$this->sendFrame($frame);
283-
return $this;
284283
}
285284

286285
private function haveToPing(): void

tests/Unit/EnvironmentTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,23 @@ public function testGetRPCAddressWithValue(): void
4545
$this->assertEquals('rpc_value', $env->getRPCAddress());
4646
}
4747

48+
public function testGetVersionWithValue(): void
49+
{
50+
$env = new Environment(['RR_VERSION' => '2024.1.3']);
51+
$this->assertEquals('2024.1.3', $env->getVersion());
52+
}
53+
4854
public function testFromGlobals(): void
4955
{
5056
$_ENV['RR_MODE'] = 'global_mode';
5157
$_SERVER['RR_RELAY'] = 'global_relay';
58+
$_SERVER['RR_VERSION'] = 'global_version';
5259

5360
$env = Environment::fromGlobals();
5461

5562
$this->assertEquals('global_mode', $env->getMode());
5663
$this->assertEquals('global_relay', $env->getRelayAddress());
64+
$this->assertEquals('global_version', $env->getVersion());
5765
$this->assertEquals('tcp://127.0.0.1:6001', $env->getRPCAddress());
5866
}
5967
}

0 commit comments

Comments
 (0)