public function buildDisableVariant(Build $build, $feature, $userValue = null)
{
if (isset($this->variants[$feature])) {
if (in_array('-' . $feature, $this->builtList)) {
return array();
}
$this->builtList[] = '-' . $feature;
$func = $this->variants[$feature];
// build the option from enabled variant,
// then convert the '--enable' and '--with' options
// to '--disable' and '--without'
$args = is_string($userValue) ? array($build, $userValue) : array($build);
if (is_string($func)) {
$disableOptions = (array) $func;
} elseif (is_callable($func)) {
$disableOptions = (array) call_user_func_array($func, $args);
} else {
throw new Exception('Unsupported variant handler type. neither string nor callable.');
}
$resultOptions = array();
foreach ($disableOptions as $option) {
// strip option value after the equal sign '='
$option = preg_replace('/=.*$/', '', $option);
// convert --enable-xxx to --disable-xxx
$option = preg_replace('/^--enable-/', '--disable-', $option);
// convert --with-xxx to --without-xxx
$option = preg_replace('/^--with-/', '--without-', $option);
$resultOptions[] = $option;
}
return $resultOptions;
}
throw new Exception("Variant {$feature} is not defined.");
}