Skip to content

Commit

Permalink
Add variable() accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Aug 28, 2021
1 parent ac057e1 commit 5eac6eb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ AWS Lambda change log

## 1.1.0 / 2021-08-28

* Added accessor for environment varibales, `Environment::variable()`
(@thekid)
* Added accessor for temporary directory, `Environment::tempDir()`
(@thekid)
* Added accessor for environment root path, `Environment::taskroot()`
Expand Down
10 changes: 10 additions & 0 deletions src/main/php/com/amazon/aws/lambda/Environment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public function tempDir(): Path {
return new Path(sys_get_temp_dir());
}

/**
* Returns a given environment variable
*
* @param string $name
* @return ?string
*/
public function variable($name) {
return $_ENV[$name] ?? null;
}

/**
* Writes a trace message
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ public function tempDir() {
Assert::instance(Path::class, (new Environment('.'))->tempDir());
}

#[Test]
public function variable() {
$_ENV['TEST']= 'true';
Assert::equals('true', (new Environment('.'))->variable('TEST'));
}

#[Test]
public function non_existant_variable() {
unset($_ENV['TEST']);
Assert::null((new Environment('.'))->variable('TEST'));
}

#[Test]
public function trace() {
$stream= new MemoryOutputStream();
Expand Down

0 comments on commit 5eac6eb

Please sign in to comment.