Stash::_run_tag PHP Method

_run_tag() private method

Run a Stash module tag with a known set of parameters
private _run_tag ( string $method, array $params = [] ) : string
$method string the public Stash method to call
$params array the tag parameters to use
return string
    private function _run_tag($method, $params = array())
    {
        // make a copy of the original parameters
        $original_params = $this->EE->TMPL->tagparams;
        // array of permitted parameters
        $allowed_params = array_flip($params);
        // set permitted params for use
        foreach ($allowed_params as $key => &$value) {
            if (isset($this->EE->TMPL->tagparams[$key])) {
                $value = $this->EE->TMPL->tagparams[$key];
            } else {
                unset($allowed_params[$key]);
            }
        }
        // overwrite template params with our safe set
        $this->EE->TMPL->tagparams = $allowed_params;
        // run the tag if it is public
        if (method_exists($this, $method)) {
            $reflection = new ReflectionMethod($this, $method);
            if (!$reflection->isPublic()) {
                throw new RuntimeException("The called method is not public.");
            }
            $out = $this->{$method}();
        }
        // restore original parameters
        $this->EE->TMPL->tagparams = $original_params;
        unset($original_params);
        return $out;
    }