php-censor/src/PHPCensor/Plugin/Env.php

47 lines
1.1 KiB
PHP
Raw Normal View History

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
/**
* Environment variable plugin
*
2017-03-04 16:39:56 +01:00
* @author Steve Kamerman <stevekamerman@gmail.com>
*/
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) {
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";
}
if (!putenv($this->builder->interpolate($env_var))) {
2013-05-19 07:47:41 +02:00
$success = false;
$this->builder->logFailure('Unable to set environment variable');
2013-05-19 07:47:41 +02:00
}
}
return $success;
}
}