统一的处理输入-输出为字符串

@param array|string $params

@return array|string
497769
private static function parseInputToString($params)
    {
        return is_array($params) ? array_map(function ($item) {
            return trim(htmlspecialchars($item, ENT_QUOTES, 'UTF-8'));
        }, $params) : trim(htmlspecialchars($params, ENT_QUOTES, 'UTF-8'));
    }
429235
public static function getModelEquation(array $params): string
    {
        return sprintf('y = %fx^%f', $params[self::$A], $params[self::$B]);
    }
1076018
private function getFullName(array $params): string
    {
        if (isset($params['full_name'])) {
            return $this->get($params, 'full_name', '');
        }

        return trim(sprintf('%s %s', $this->get($params, 'first', ''), $this->get($params, 'last', '')));
    }
869190
protected function encodePayload(array $params)
  {
    $encoded = [];
    foreach ($params as $key => $value)
    {
      if (is_array($value))                 $encoded[$key] = $this->encodePayload($value);
      else if ($value instanceof \DateTime) $encoded[$key] = $value->format(\DateTime::ISO8601);
      else                                  $encoded[$key] = $value;
    }

    return $encoded;
  }
599666
public function getCallable($params = [])
    {
        $className = $this->className;
        $methodName = $this->methodName;
        foreach($params as $name => $value)
        {
            $className = str_replace('{$' . $name . '}', $value, $className);
            $methodName = str_replace('{$' . $name . '}', $value, $methodName);
        }
        return [RequestContext::getServer()->getBean($className), $methodName];
    }
180141
public static function makeUrl(array $params): string
    {
        $href = [];

        foreach ($params as $key => $value) {
            $href[] = static::makeParam($key, (string)$value);
        }

        return '?' . implode('&', $href);
    }
1033129
public static function parse($params = [])
	{
		$obj = new Request();

		$obj->id = $params['id'];
		$obj->type = (int) $params['type'];

		switch ($obj->type) {
			case 1:
				$obj->name = $params['name'];
				$obj->url = $params['url'];
				$obj->method = strtoupper(trim($params['method']));

				$obj->setAuthorization($params['authorization']);
				$obj->setProxy($params['proxy']);
				$obj->setTimeout(empty($params['timeout']) ? null : $params['timeout']);

				// 设置默认请求头
				// $obj->headers['Content-Type'] = 'text/plain';

				// 处理请求数据
				switch ($obj->method)
				{
					// 这两种类型无需对参数做处理
					case Method::GET:
					case Method::HEAD:
						foreach( (array) $params['data'] as $item )
						{
							if ( 'text' == $item['type'] )
							{
								$obj->data[ $item['key'] ] = $item['value'];
							}
							else
							{
								// 暂未实现
							}
						}
						break;

					// 只有 PUT,POST,DELETE,OPTIONS,PATCH 支持内容体
					case Method::POST:
					case Method::PUT:
					case Method::DELETE:
					case Method::OPTIONS:
						$dataMode = strtolower( trim($params['dataMode']) );
						switch ($dataMode) {
							case 'params':
								foreach( (array) $params['data'] as $item )
								{
									if ( 'text' == $item['type'] )
									{
										$obj->data[ $item['key'] ] = $item['value'];
									}
									else if ( 'file' == $item['type'] )
									{
										$obj->headers['Content-Type'] = 'multipart/form-data';
										// file 内容暂不支持
									}
								}
								break;
							case 'urlencoded':
								$obj->headers['Content-Type'] = 'application/x-www-form-urlencoded';
								foreach( (array) $params['data'] as $item )
								{
									if ( 'text' == $item['type'] )
									{
										$obj->data[ $item['key'] ] = $item['value'];
									}
								}
								break;

							case 'raw-json':
								$obj->headers['Content-Type'] = 'application/json';
								$obj->data = $params['data']['value'];
								break;
							case 'raw-xml':
								$obj->headers['Content-Type'] = 'application/xml';
								$obj->data = $params['data']['value'];
								break;
							case 'raw-textxml':
								$obj->headers['Content-Type'] = 'text/xml';
								$obj->data = $params['data']['value'];
								break;
							case 'raw-html':
								$obj->headers['Content-Type'] = 'text/html';
								$obj->data = $params['data']['value'];
								break;							
							case 'raw-text':
								$obj->headers['Content-Type'] = 'text/plain';
								$obj->data = $params['data']['value'];
								break;
							case 'raw-binary':
							default:
								throw new Exception("Not supported request `dataMode`: {$dataMode}");
								break;
						}

						break;
					default:
						throw new Exception("Not supported request `method`: {$obj->method}");
						break;
				}

				// 设置请求头
				foreach( (array) $params['headers'] as $key => $val )
				{
					$obj->headers[$key] = $val;
				}

				// 设置断言规则
				
				// 设置变量提取规则

				break;
			case 2:
				$obj->delay = (int) $params['delay'];
				break;
			default:
				throw new Exception("Unknown request `type`: {$obj->type}");
				break;
		}

		return $obj;
	}
1188784
private function mode($params) {

		$mode = 'params';

	 	if(count($params) > 0 && 0 === count(array_filter(array_keys($params), 'is_string'))) {
	 		$mode = 'bind';
	 	}

	 	return $mode;
	}
400438
protected function actionGet($params=array())
    {
        $response = array(
            'errors'=>array(),
            'data' => array(
                'count' => 0,
                'items' => array(),
            ),
        );
        $offset = isset($params['offset'])?(int)$params['offset']:0;
        if ($offset < 0) $offset = 0;
        $count = isset($params['count'])?(int)$params['count']:100;
        if ($count < 1) $count = 1;
        if ($count > 100) $count = 100;
        $filter = array(
            'fields' => array(),
            'offset' => $offset,
            'count' => $count,
        );
        $idsRaw = isset($params['ids'])?(string)$params['ids']:null;
        $idsRaw = preg_replace('/[^a-f0-9\,]/ui','',$idsRaw);
        $idsRaw = preg_replace('/^\,+|\,+$/ui','',$idsRaw);
        $idsRaw = preg_replace('/\,+/ui',',',$idsRaw);
        if (!empty($idsRaw)) {
            $ids = explode(',',$idsRaw);
            if (count($ids) > 1) {
                $filter['fields'][] = array(
                    'field' => 'id',
                    'compare' => 'in',
                    'value' => $ids,
                );
            } elseif (count($ids) == 1) {
                $filter['fields'][] = array(
                    'field' => 'id',
                    'compare' => '=',
                    'value' => $ids[0],
                );
            }
        }
        $street = isset($params['street'])?trim((string)$params['street']):null;
        $number = isset($params['number'])?trim((string)$params['number']):null;

        if ($street && !$number) {
            $filter['fields'][] = array(
                'field' => 'street',
                'compare' => '=',
                'value' => $street,
            );
        }
        if (!$street && $number) {
            $filter['fields'][] = array(
                'field' => 'number',
                'compare' => '=',
                'value' => $street,
            );
        }
        if ($street && $number) {
            $filter['fields'][] = array(
                'field' => 'id',
                'compare' => '=',
                'value' => $this->build->getId(array('street'=>$street,'number'=>$number)),
            );
        }
        $response['data']['count'] = $this->build->count($filter);
        $builds = $this->build->find($filter);
        $response['data']['items'] = $builds;
        return $response;
    }
57891
public function get($url, $params = [])
    {
        if (is_array($url)) {
            return $this->mget($url, $params);
        }
        return $this->exec($this->buildRequest('GET', $url, $params));
    }
1170074
public function getRealParams(array $params)
    {
        foreach ($params as $k => $p) {
            if (is_array($p)) {
                $params[$k] = $p[1];
            }
        }

        return $params;
    }
807372
protected function buildQueryString(array $params)
    {
        $qs = "";
        foreach ($params as $key => $value) {
            if ($qs === "") {
                $qs = "?";
            } else {
                $qs .= "&&";
            }
            $qs .= $key . "=" . $value;
        }
        return $qs;
    }
1129567
public function getParam(string $param)
    {
        if (! empty($this->match['params'][$param])) {
            return $this->match['params'][$param];
        }
    }
748927
protected function getHeaders($params)
    {
        $headers = array();
        
        foreach ($params as $name => $value) {
            if (substr($name, 0, 5) === 'HTTP_') {
                $key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
                $headers[$key] = $value;
            }
        }
        
        return $headers;
    }
668601
public function request($params)
  {
    $query = array_merge($params, [
      'key' => $this->key
    ]);

    try {

      $response = $this->client->get(self::API_ENDPOINT, [
        'query' => $query
      ]);

    } catch (ClientException $exception) {

      return collect([]);

    }

    $results = json_decode($response->getBody(), true);

    $output = [];

    for($i = 0; $i < count($results['itemListElement']); $i++) {
      $output[] = new SearchResult($results['itemListElement'][$i]);
    }

    return collect($output);
  }
376944
public function singleton($params = [])
    {
        static $instances = [];

        $signature = serialize($params);
        if (!isset($instances[$signature])) {
            $instances[$signature] = idna_convert::getInstance($params);
        }

        return $instances[$signature];
    }
826399
public function getSignature(array $params)
    {
        ksort($params);
        $signature = md5($this->parameters->getAuth('secret') . json_encode($params));

        return $signature;
    }