forked from php-censor/php-censor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnv.php
More file actions
44 lines (39 loc) · 1.07 KB
/
Copy pathEnv.php
File metadata and controls
44 lines (39 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace PHPCensor\Plugin;
use PHPCensor\Plugin;
/**
* Environment variable plugin
*
* @author Steve Kamerman <stevekamerman@gmail.com>
*/
class Env extends Plugin
{
/**
* @return string
*/
public static function pluginName()
{
return 'env';
}
/**
* Adds the specified environment variables to the builder environment
*/
public function execute()
{
$success = true;
foreach ($this->options as $key => $value) {
if (is_numeric($key)) {
// This allows the developer to specify env vars like " - FOO=bar" or " - FOO: bar"
$envVar = is_array($value)? key($value).'='.current($value): $value;
} else {
// This allows the standard syntax: "FOO: bar"
$envVar = "$key=$value";
}
if (!putenv($this->builder->interpolate($envVar))) {
$success = false;
$this->builder->logFailure('Unable to set environment variable');
}
}
return $success;
}
}