Overload to verify if the current url matches the expected one. Throw an exception otherwise.

@param array $urlParameters
198734
protected function verifyUrl(array $urlParameters = array())
    {
        $expectedUrl = $this->getUrl($urlParameters);
        $currentUrl = $this->getDriver()->getCurrentUrl();

        if ($currentUrl !== $expectedUrl) {
            throw new UnexpectedPageException(sprintf('Expected to be on "%s" but found "%s" instead', $expectedUrl, $currentUrl));
        }
    }
328611
public function setParameters($parameters)
    {
        // type check, error must never occur, bad code of it does
        if (!is_array($parameters)) {
            throw new Exception("Expected parameters array got something else");
        }

        $this->_parameters = $parameters;
        $this->setInitialized(false);
    }
1273418
protected function getCustomUrl(array $urlParameters = array())
    {
        $urlParameters = $this->addRequestVariablesToUrlParameters($urlParameters);

        if ($this->customUrl && count($urlParameters) > 0)
        {
            $params = http_build_query($urlParameters);

            if ('' != parse_url($this->customUrl, PHP_URL_QUERY))
            {
                // existing query string, append
                return $this->customUrl.'&'.$params;
            }

            return $this->customUrl.'?'.$params;
        }

        return $this->customUrl;
    }
802040
public function buildUrlWithParameters(array $parameters = [])
    {
        $url = $this->url;

        if (!$this->hasParameters() && !$parameters) {
            return $url;
        }

        foreach ($parameters as $key => $value) {
            $url = str_replace('{' . $key . '}', $value, $url);
        }
        return $url;
    }
909561
protected static function parseArgvIntoParameters(): void
    {
        if (static::$parameters === null) {
            static::$parameters = [];
            $argv = static::getArgv();
            array_shift($argv); // remove the script name, it's not needed
            $sizeof = count($argv);

            for ($i = 0; $i < $sizeof; $i++) {
                $p = $argv[$i];

                if (substr($p, 0, 2) == '--') {
                    $tmp = explode('=', $p);
                    static::$parameters[substr($tmp[0], 2)] = $tmp[1] ?? null;

                } else if (substr($p, 0, 1) == '-' && isset($argv[$i + 1]) && substr($argv[$i + 1], 0, 1) != '-') {
                    static::$parameters[substr($p, 1)] = $argv[$i + 1] ?? null;

                } else if (substr($p, 0, 1) == '-' && preg_match('/^[a-zA-Z]$/', substr($p, 1, 1))) {
                    static::$parameters[substr($p, 1, 1)] = null;

                }

            }
        }
    }
397753
public function init(array $params = array()) {
        if (count($params) !== count($this->_config)) {
            throw new Garp_Browsebox_Exception('Number of parameters does not match the number of required parameters in filter "'.$this->getId().'"');
        }
        $this->_values = $params;
    }
202340
private static function _checkParams(array $params) : void
    {
        // check existence of mandatory parameters

        // driver
        if (! isset($params['driver']) && ! isset($params['driverClass'])) {
            throw DBALException::driverRequired();
        }

        // check validity of parameters

        // driver
        if (isset($params['driver']) && ! isset(self::$_driverMap[$params['driver']])) {
            throw DBALException::unknownDriver($params['driver'], array_keys(self::$_driverMap));
        }

        if (isset($params['driverClass']) && ! in_array(Driver::class, class_implements($params['driverClass'], true))) {
            throw DBALException::invalidDriverClass($params['driverClass']);
        }
    }
533289
private function _invoke($urlParams) {

        $serviceClassPath = APP_NAME."\\api\\service\\".ucfirst($urlParams[0])."Service";
        try {
            $service = Loader::service($serviceClassPath);
        } catch(\Exception $e) {
            throw new APIException(404, "Can not find the servive '{$serviceClassPath}'.");
        }
        $params = $_GET + $_POST; //获取参数

        //检查当前模块下是否有监听器，如果有则加载监听器
        $lisennerClassName = APP_NAME."\\api\\ModuleListener";
        $listener = null;
        try {
            $reflect = new \ReflectionClass($lisennerClassName);
            $listener = $reflect->newInstance();
        } catch (\ReflectionException $exception) {
            //__print($exception);die();
        }
        // 这里做拦截和权限认证操作
        if ( $listener->needAuthrize("/{$urlParams[0]}/{$urlParams[1]}") ) {
            if ( !$listener->authorize($params) ) {
                throw new APIException(401, "Authorized Faild.");
            }
        }

        try {
            $reflectMethods = new \ReflectionMethod($service, $urlParams[1]);
            $dependParams = array(); //依赖参数
            foreach ($reflectMethods->getParameters() as $value) {
                if (isset($params[$value->getName()])) { // 传入的参数的名称要跟服务方法的参数名相同
                    $dependParams[] = $params[$value->getName()];
                } else if ($value->isDefaultValueAvailable()) {
                    $dependParams[] = $value->getDefaultValue();
                } else {
                    $dependParams[] = null;
                }
            }
            $result = call_user_func_array(array($service, $urlParams[1]), $dependParams);
        } catch (\Exception $e) {
            throw new APIException(500, $e->getMessage());
        }
        $result->output();  //输出json数据
    }
455520
public function updateURLWithParameters($url, array $params)
    {
        if (empty($params)) {
            return $url;
        }

        $parts = parse_url($url);

        $scheme = isset($parts['scheme']) ? $parts['scheme'] : null;
        if ($scheme) {
            $scheme .= ':';
        }

        $host = isset($parts['host']) ? $parts['host'] : null;
        if ($host) {
            $host = "//$host";
        }
        $path = isset($parts['path']) ? $parts['path'] : null;

        //Merge parameters
        $query = isset($parts['query']) ? $parts['query'] : null;
        $params += $this->getParameterFromQuery($query);
        if (!empty($params)) {
            $query = '?' . http_build_query($params);
        }

        $fragment = isset($parts['fragment']) ? $parts['fragment'] : null;
        if ($fragment) {
            $fragment = "#$fragment";
        }

        return "{$scheme}{$host}{$path}{$query}$fragment";
    }
889213
protected function checkRemoteURlsToImport(array $urls)
    {
        foreach ($urls as $u) {
            try {
                $url = Url::createFromUrl($u);
            } catch (RuntimeException $x) {
                throw new UserMessageException(t('The URL "%s" is not valid: %s', $u, $x->getMessage()));
            }
            $scheme = (string) $url->getScheme();
            if ($scheme === '') {
                throw new UserMessageException(t('The URL "%s" is not valid.', $u));
            }
            $host = trim((string) $url->getHost());
            if (in_array(strtolower($host), ['', '0', 'localhost'], true)) {
                throw new UserMessageException(t('The URL "%s" is not valid.', $u));
            }
            $ip = IPFactory::addressFromString($host);
            if ($ip === null) {
                $dnsList = @dns_get_record($host, DNS_A | DNS_AAAA);
                while ($ip === null && $dnsList !== false && count($dnsList) > 0) {
                    $dns = array_shift($dnsList);
                    $ip = IPFactory::addressFromString($dns['ip']);
                }
            }
            if ($ip !== null && !in_array($ip->getRangeType(), [IPRangeType::T_PUBLIC, IPRangeType::T_PRIVATENETWORK], true)) {
                throw new UserMessageException(t('The URL "%s" is not valid.', $u));
            }
        }
    }
97992
public function generateUrl($urlParams = array(), $customAction = null)
    {
        return $this->resourceUrl . ($customAction ? "/$customAction" : '') . '.json' . (!empty($urlParams) ? '?' . http_build_query($urlParams) : '');
    }
750590
private function preOpMethodParamsCheck($params)
    {
        $this->MathCheck();

        foreach ($params as $key => $value) {
            if ($this->numberCheck($value) === false) {
                $caller = debug_backtrace();
                throw new \Exception('Empty or invalid parameters passed to ' . $caller[count($caller) - 1]['function'] . ' function. Argument list received: ' . var_export($caller[count($caller) - 1]['args'], true));
            }
        }
    }
627718
public function parseParameters(array $parameters = [], $possibleAlias = [])
    {
        if (count($parameters) == 0) {
            $parameters = $this->getPossibleParams();
        }

        $arguments = [];
        foreach ($parameters as $parameter => $description) {
            if (strpos($parameter, "=") !== false) {
                $parameterParts = explode("=", $parameter);
                if (count($parameterParts) != 2) {
                    throw new CommandsException("Invalid definition for the parameter '$parameter'");
                }
                if (strlen($parameterParts[0]) == "") {
                    throw new CommandsException("Invalid definition for the parameter '$parameter'");
                }
                if (!in_array($parameterParts[1], ['s', 'i', 'l'])) {
                    throw new CommandsException("Incorrect data type on parameter '$parameter'");
                }
                $this->_preparedArguments[$parameterParts[0]] = true;
                $arguments[$parameterParts[0]] = [
                    'have-option' => true,
                    'option-required' => true,
                    'data-type' => $parameterParts[1]
                ];
            } else {
                if (!preg_match('/([a-zA-Z0-9]+)/', $parameter)) {
                    throw new CommandsException("Invalid parameter '$parameter'");
                }

                $this->_preparedArguments[$parameter] = true;
                $arguments[$parameter] = [
                    'have-option'     => false,
                    'option-required' => false
                ];
            }
        }

        $param = '';
        $paramName = '';
        $receivedParams = [];
        $numberArguments = count($_SERVER['argv']);

        for ($i = 1; $i < $numberArguments; $i++) {
            $argv = $_SERVER['argv'][$i];
            if (preg_match('#^([\-]{1,2})([a-zA-Z0-9][a-zA-Z0-9\-]*)(=(.*)){0,1}$#', $argv, $matches)) {
                if (strlen($matches[1]) == 1) {
                    $param = substr($matches[2], 1);
                    $paramName = substr($matches[2], 0, 1);
                } else {
                    if (strlen($matches[2]) < 2) {
                        throw new CommandsException("Invalid script parameter '$argv'");
                    }
                    $paramName = $matches[2];
                }

                if (!isset($this->_preparedArguments[$paramName])) {
                    if (!isset($possibleAlias[$paramName])) {
                        throw new CommandsException("Unknown parameter '$paramName'");
                    }
                    $paramName = $possibleAlias[$paramName];
                }

                if (isset($arguments[$paramName])) {
                    if ($param != '') {
                        $receivedParams[$paramName] = $param;
                        $param = '';
                        $paramName = '';
                    }
                    if ($arguments[$paramName]['have-option'] == false) {
                        $receivedParams[$paramName] = true;
                    } elseif (isset($matches[4])) {
                        $receivedParams[$paramName] = $matches[4];
                    }
                }
            } else {
                $param = $argv;
                if ($paramName != '') {
                    if (isset($arguments[$paramName])) {
                        if ($param == '') {
                            if ($arguments[$paramName]['have-option'] == true) {
                                throw new CommandsException("The parameter '$paramName' requires an option");
                            }
                        }
                    }
                    $receivedParams[$paramName] = $param;
                    $param = '';
                    $paramName = '';
                } else {
                    $receivedParams[$i - 1] = $param;
                    $param = '';
                }
            }
        }

        $this->_parameters = $receivedParams;

        return $receivedParams;
    }
146786
protected function unmaskUrl(array $urlParameters)
    {
        $url = $this->getPath();

        foreach ($urlParameters as $parameter => $value) {
            $url = str_replace(sprintf('{%s}', $parameter), $value, $url);
        }

        return $url;
    }
29283
public function loadUrlAliasData(array $urlHashes)
    {
        try {
            return $this->innerGateway->loadUrlAliasData($urlHashes);
        } catch (DBALException $e) {
            throw new \RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new \RuntimeException('Database error', 0, $e);
        }
    }
1075529
public static function check(array $pParams)
    {
        foreach ($pParams as $type => $value) {
            $func = 'is' . $type;

            if (method_exists(__CLASS__, $func)) {
                if (is_array($value)) {
                    foreach ($value as $subValue) {
                        if (self::$func($subValue) === false) {
                            return false;
                        }
                    }
                } else if (self::$func($value) === false) {
                    return false;
                }
            } else {
                if (! self::isRegex($type, $value)) {
                    return false;
                }
            }
        }

        return true;
    }
816341
public function checkUrls($urls)
    {
        $urls = $this->cleanParameterUrls($urls);

        foreach ($urls as $url) {
            if (!UrlHelper::isLookLikeUrl($url)) {
                throw new Exception(sprintf(Piwik::translate('SitesManager_ExceptionInvalidUrl'), $url));
            }
        }
    }