Piwik\API\Proxy::getRequestParametersArray PHP Method

getRequestParametersArray() private method

Returns an array containing the values of the parameters to pass to the method to call
private getRequestParametersArray ( array $requiredParameters, array $parametersRequest ) : array
$requiredParameters array array of (parameter name, default value)
$parametersRequest array
return array values to pass to the function call
    private function getRequestParametersArray($requiredParameters, $parametersRequest)
    {
        $finalParameters = array();
        foreach ($requiredParameters as $name => $defaultValue) {
            try {
                if ($defaultValue instanceof NoDefaultValue) {
                    $requestValue = Common::getRequestVar($name, null, null, $parametersRequest);
                } else {
                    try {
                        if ($name == 'segment' && !empty($parametersRequest['segment'])) {
                            // segment parameter is an exception: we do not want to sanitize user input or it would break the segment encoding
                            $requestValue = $parametersRequest['segment'];
                        } else {
                            $requestValue = Common::getRequestVar($name, $defaultValue, null, $parametersRequest);
                        }
                    } catch (Exception $e) {
                        // Special case: empty parameter in the URL, should return the empty string
                        if (isset($parametersRequest[$name]) && $parametersRequest[$name] === '') {
                            $requestValue = '';
                        } else {
                            $requestValue = $defaultValue;
                        }
                    }
                }
            } catch (Exception $e) {
                throw new Exception(Piwik::translate('General_PleaseSpecifyValue', array($name)));
            }
            $finalParameters[$name] = $requestValue;
        }
        return $finalParameters;
    }