DataSift\Storyplayer\Cli\Feature_DefineSwitch::process PHP Method

process() public method

public process ( Phix_Project\CliEngine $engine, integer $invokes = 1, array $params = [], boolean $isDefaultParam = false ) : Phix_Project\CliEngine\CliResult
$engine Phix_Project\CliEngine
$invokes integer
$params array
$isDefaultParam boolean
return Phix_Project\CliEngine\CliResult
    public function process(CliEngine $engine, $invokes = 1, $params = array(), $isDefaultParam = false)
    {
        if (!isset($engine->options->defines)) {
            $engine->options->defines = new stdClass();
        }
        foreach ($params as $param) {
            // split up the setting
            $parts = explode('=', $param);
            $key = array_shift($parts);
            $value = implode('=', $parts);
            // do we want to convert the type of $value?
            $lowerValue = strtolower($value);
            if ($lowerValue == 'false') {
                $value = false;
            } else {
                if ($lowerValue == 'true') {
                    $value = true;
                } else {
                    if ($lowerValue == 'null') {
                        $value = null;
                    }
                }
            }
            // expand dot notation
            $parts = explode('.', $key);
            $currentLevel = $engine->options->defines;
            $lastPart = array_pop($parts);
            foreach ($parts as $part) {
                $currentLevel->{$part} = new stdClass();
                $currentLevel = $currentLevel->{$part};
            }
            // store the value into the tree
            $currentLevel->{$lastPart} = $value;
        }
        // tell the engine that it is done
        return new CliResult(CliResult::PROCESS_CONTINUE);
    }
Feature_DefineSwitch