2013-05-19 07:47:41 +02:00
|
|
|
<?php
|
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
namespace PHPCensor\Plugin;
|
2013-05-19 07:47:41 +02:00
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
use PHPCensor\Plugin;
|
2013-10-10 02:01:06 +02:00
|
|
|
|
2013-05-19 07:47:41 +02:00
|
|
|
/**
|
2017-01-10 18:46:19 +01:00
|
|
|
* Environment variable plugin
|
|
|
|
*
|
2017-03-04 16:39:56 +01:00
|
|
|
* @author Steve Kamerman <stevekamerman@gmail.com>
|
2017-01-10 18:46:19 +01:00
|
|
|
*/
|
2016-07-11 18:00:04 +02:00
|
|
|
class Env extends Plugin
|
2013-05-19 07:47:41 +02:00
|
|
|
{
|
|
|
|
protected $env_vars;
|
|
|
|
|
2017-01-11 16:15:54 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function pluginName()
|
|
|
|
{
|
|
|
|
return 'env';
|
|
|
|
}
|
|
|
|
|
2013-05-19 07:47:41 +02:00
|
|
|
/**
|
|
|
|
* Adds the specified environment variables to the builder environment
|
|
|
|
*/
|
|
|
|
public function execute()
|
|
|
|
{
|
|
|
|
$success = true;
|
2016-07-11 18:00:04 +02:00
|
|
|
foreach ($this->options as $key => $value) {
|
2013-05-19 22:54:35 +02:00
|
|
|
if (is_numeric($key)) {
|
|
|
|
// This allows the developer to specify env vars like " - FOO=bar" or " - FOO: bar"
|
|
|
|
$env_var = is_array($value)? key($value).'='.current($value): $value;
|
|
|
|
} else {
|
|
|
|
// This allows the standard syntax: "FOO: bar"
|
|
|
|
$env_var = "$key=$value";
|
|
|
|
}
|
2015-10-23 05:18:22 +02:00
|
|
|
|
2016-07-22 09:05:34 +02:00
|
|
|
if (!putenv($this->builder->interpolate($env_var))) {
|
2013-05-19 07:47:41 +02:00
|
|
|
$success = false;
|
2017-02-07 13:05:44 +01:00
|
|
|
$this->builder->logFailure('Unable to set environment variable');
|
2013-05-19 07:47:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $success;
|
|
|
|
}
|
|
|
|
}
|