2013-05-19 07:47:41 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2014-05-12 18:26:17 +02:00
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2014, Block 8 Limited.
|
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link https://www.phptesting.org/
|
|
|
|
*/
|
2013-05-19 07:47:41 +02:00
|
|
|
|
|
|
|
namespace PHPCI\Plugin;
|
|
|
|
|
2013-10-10 02:01:06 +02:00
|
|
|
use PHPCI\Builder;
|
2014-12-04 16:48:52 +01:00
|
|
|
use PHPCI\Helper\Lang;
|
2013-10-10 02:01:06 +02:00
|
|
|
use PHPCI\Model\Build;
|
|
|
|
|
2013-05-19 07:47:41 +02:00
|
|
|
/**
|
|
|
|
* Environment variable plugin
|
|
|
|
* @author Steve Kamerman <stevekamerman@gmail.com>
|
|
|
|
* @package PHPCI
|
|
|
|
* @subpackage Plugins
|
|
|
|
*/
|
|
|
|
class Env implements \PHPCI\Plugin
|
|
|
|
{
|
|
|
|
protected $phpci;
|
2014-05-02 15:48:40 +02:00
|
|
|
protected $build;
|
2013-05-19 07:47:41 +02:00
|
|
|
protected $env_vars;
|
|
|
|
|
2014-12-08 12:25:33 +01:00
|
|
|
/**
|
|
|
|
* Set up the plugin, configure options, etc.
|
|
|
|
* @param Builder $phpci
|
|
|
|
* @param Build $build
|
|
|
|
* @param array $options
|
|
|
|
*/
|
2013-10-10 02:01:06 +02:00
|
|
|
public function __construct(Builder $phpci, Build $build, array $options = array())
|
2013-05-19 07:47:41 +02:00
|
|
|
{
|
2014-05-02 15:48:40 +02:00
|
|
|
$this->phpci = $phpci;
|
|
|
|
$this->build = $build;
|
2013-05-19 07:47:41 +02:00
|
|
|
$this->env_vars = $options;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the specified environment variables to the builder environment
|
|
|
|
*/
|
|
|
|
public function execute()
|
|
|
|
{
|
|
|
|
$success = true;
|
2013-05-19 22:54:35 +02:00
|
|
|
foreach ($this->env_vars 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";
|
|
|
|
}
|
2013-05-19 07:47:41 +02:00
|
|
|
|
2013-05-22 21:54:18 +02:00
|
|
|
if (!putenv($this->phpci->interpolate($env_var))) {
|
2013-05-19 07:47:41 +02:00
|
|
|
$success = false;
|
2014-12-04 16:48:52 +01:00
|
|
|
$this->phpci->logFailure(Lang::get('unable_to_set_env'));
|
2013-05-19 07:47:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $success;
|
|
|
|
}
|
|
|
|
}
|