Send and parse the request pool

@return \StdClass
5815
public function send()
    {
        $responses = new \StdClass();

        foreach ($this->resources as $key => $promise) {
            $response = $promise->wait();
            $responses->{$key} = $this->parse($response->getBody());
        }

        return $responses;
    }
18594
public function send() :bool {

		// initialize
		$this->initializeCurl();
		$this->configureCurl();
		
		// run & parse
		return $this->parseCurl($this->executeCurl());
		
	}
1346272
public function send()
    {

        $this->ok = false;
// Try using curl if available
        if (function_exists('curl_init')) {
            $resp = '';
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $this->url);
            if (!empty($this->requestHeaders)) {
                curl_setopt($ch, CURLOPT_HTTPHEADER, $this->requestHeaders);
            } else {
                curl_setopt($ch, CURLOPT_HEADER, 0);
            }
            if ($this->method === 'POST') {
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $this->request);
            } else if ($this->method !== 'GET') {
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->method);
                if (!is_null($this->request)) {
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $this->request);
                }
            }
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLINFO_HEADER_OUT, true);
            curl_setopt($ch, CURLOPT_HEADER, true);
            $chResp = curl_exec($ch);
            $this->ok = $chResp !== false;
            if ($this->ok) {
                $chResp = str_replace("\r\n", "\n", $chResp);
                $chRespSplit = explode("\n\n", $chResp, 2);
                if ((count($chRespSplit) > 1) && (substr($chRespSplit[1], 0, 5) === 'HTTP/')) {
                    $chRespSplit = explode("\n\n", $chRespSplit[1], 2);
                }
                $this->responseHeaders = $chRespSplit[0];
                $resp = $chRespSplit[1];
                $this->status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                $this->ok = $this->status < 400;
                if (!$this->ok) {
                    $this->error = curl_error($ch);
                }
            }
            $this->requestHeaders = str_replace("\r\n", "\n", curl_getinfo($ch, CURLINFO_HEADER_OUT));
            curl_close($ch);
            $this->response = $resp;
        } else {
// Try using fopen if curl was not available
            $opts = array('method' => $this->method,
                          'content' => $this->request
                         );
            if (!empty($this->requestHeaders)) {
                $opts['header'] = $this->requestHeaders;
            }
            try {
                $ctx = stream_context_create(array('http' => $opts));
                $fp = @fopen($this->url, 'rb', false, $ctx);
                if ($fp) {
                    $resp = @stream_get_contents($fp);
                    $this->ok = $resp !== false;
                }
            } catch (\Exception $e) {
                $this->ok = false;
            }
        }

        return $this->ok;

    }
1299086
public function load(): Request
    {
        global $argv;

        $this
            ->setArgs($argv)
            ->setContent(file_get_contents('php://input'));

        if (isset($_COOKIE)) {
            $this->setCookies($_COOKIE);
        }

        // @codeCoverageIgnoreStart
        if (isset($_SESSION)) {
            $this->setSession($_SESSION);
        }
        // @codeCoverageIgnoreEnd

        if (isset($_GET)) {
            $this->setGet($_GET)->setStage($_GET);
        }

        if (isset($_POST)) {
            $this->setPost($_POST)->setStage($_POST);
        }

        if (isset($_FILES)) {
            $this->setFiles($_FILES);
        }

        if (isset($_SERVER)) {
            $this->setServer($_SERVER);
        }

        return $this;
    }
640130
private function _parseTokenFromRequest()
    {
        if ($this->_c_parsedToken)
            // From Cached
            return $this->_c_parsedToken;


        $this->_c_parsedToken = $r = $this->assertion->parseTokenStrFromRequest(
            new ServerRequestBridgeInPsr( $this->request() )
        );

        return $r;
    }
44560
private function makeHttpRequest()
    {
        try {
            return $this->client->post($this->apiUrl, [
                'json'    => $this->post->toArray(),
                'headers' => $this->setHeaders(),
            ])->getBody();
        } catch (\GuzzleHttp\Exception\ClientException $e) {
            throw new \Exception(collect($e->getTrace())->implode('\n'));
        } catch (\GuzzleHttp\Exception\ServerException $e) {
            throw new \Exception(collect($e->getTrace())->implode('\n'));
        } catch (\GuzzleHttp\Exception\BadResponseException $e) {
            throw new \Exception(collect($e->getTrace())->implode('\n'));
        }
    }
905390
public function parse()
    {
        $result = new stdClass();
        $cache = $parser = $exception = $cacheKey = $path = null;
        try {
            $path = $this->find(false);
            // Cached response
            $cache = new PathCache(__FUNCTION__, $this->options);
            $cacheKey = $cache->getKey([$path]);
            $result = $cache->readFrom($cacheKey);
            if ($result !== false) {
                return $result;
            }
            // Real response
            $parser = $this->getParser();
            $result = $parser->parse($path);
        } catch (InvalidArgumentException $exception) {
            $this->mergeMessages($exception, __FUNCTION__);
        }
        $this->mergeMessages($parser, __FUNCTION__);
        $this->mergeMessages($cache, __FUNCTION__);

        // Re-throw parser exception
        if ($exception) {
            throw $exception;
        }

        if ($cache && $cacheKey) {
            $cache->writeTo($cacheKey, $result, ['path' => $path]);
        }

        return $result;
    }
1227542
public function send()
    {
        $request = $this->guzzleClient->createRequest('GET', self::TRENDS_URL, ['cookies' => $this->session->getCookieJar()]);
        $query = $request->getQuery();

        $params = [
            'hl'        =>  $this->language,
            'q'         =>  implode(',+', $this->query),
            'cid'       =>  $this->cid,
            'date'      =>  $this->dateRange,
            'cmpt'      =>  'q',
            'content'   =>  '1',
            'export'    =>  '3',
        ];

        !$this->category ?: $params['cat'] = $this->category;
        !$this->location ?: $params['geo'] = $this->location;

        foreach ($params as $key => $param) {
            $query->set($key, $param);
        }

        // wait a random amount of seconds
        if ($this->session->getMaxSleepInterval() > 10) {
            sleep(rand(10, $this->session->getMaxSleepInterval())/100);
        }

        $response = $this->guzzleClient->send($request);
        $content = $response->getBody()->getContents();

        // quota limit error
        if ($response->getStatusCode() == 203 && strpos($content, 'You have reached your quota limit.') !== false) {
            throw new BadResponseException('You have reached your quota limit. Please try again later.', $request, $response);
        }

        // other error
        if (strpos($content, '"status":"error"') !== false) {
            $content = substr($content, strpos($content, '({') + 1, -2);
            $content = @json_decode($content, true);

            $errorMsg = $content['errors'][0]['message'] . '. ';
            !isset($content['errors'][0]['detailed_message']) ?:  $errorMsg .= $content['errors'][0]['detailed_message'];

            throw new BadResponseException($errorMsg, $request, $response);
        }

        return new GoogleTrendsResponse($response, $content);
    }
977807
public function parse() {
		/** @noinspection PhpParamsInspection */
		return $this -> execute(Util::cache(
			$this -> file,
			$this -> raw,
			'viper',
			function($data): NodeCollection {
				$tokens = $this -> tokenize($data);
				return $this -> formLogicalTree($tokens);
			}
		), $this -> data);
	}
485209
protected function parseRequest()
    {
        if ($this->customParams === false) {
            // pull various supported inputs from post
            $request = $this->di->get('request');

            // only process if it is a get
            if ($request->isGet() == false) {
                return;
            }
        } else {
            $_REQUEST = $_GET = $this->customParams;
            $request = $this->di->get('request');
        }

        // simple stuff first
        $with = $request->get('with', "string", null);
        $include = $request->get('include', "string", null);
        if (!is_null($with)) {
            $this->suppliedWith = $with;
        } elseif (!is_null($include)) {
            $this->suppliedWith = $include;
        }

        // load possible sort values in the following order
        // be sure to mark this as a paginated result set
        if ($request->get('sort', "string", null) != null) {
            $this->suppliedSort = $request->get('sort', "string", null);
            $this->isPager = true;
        } elseif ($request->get('sort_field', "string", null) != null) {
            $this->suppliedSort = $request->get('sort_field', "string", null);
            $this->isPager = true;
        } elseif ($request->get('sortField', "string", null) != null) {
            $this->suppliedSort = $request->get('sortField', "string", null);
            $this->isPager = true;
        }

        // prep for the harder stuff
        // ?page=1&perPage=25&orderAscending=false

        // load possible limit values in the following order
        // be sure to mark this as a paginated result set
        if ($request->get('limit', "string", null) != null) {
            $this->suppliedLimit = $request->get('limit', "string", null);
            $this->isPager = true;
        } elseif ($request->get('per_page', "string", null) != null) {
            $this->suppliedLimit = $request->get('per_page', "string", null);
            $this->isPager = true;
        } elseif ($request->get('perPage', "string", null) != null) {
            $this->suppliedLimit = $request->get('perPage', "string", null);
            $this->isPager = true;
        }

        // look for string that means to show all records
        if ($this->isPager) {
            if ($this->suppliedLimit == 'all') {
                $this->suppliedLimit = 9999999999;
            }
        }

        // load offset values in the following order
        // Notice that a page is treated differently than offset
        // $this->offset = ($offset != null) ? $offset : $this->offset;
        if ($request->get('offset', "int", null) != null) {
            $this->suppliedOffset = $request->get('offset', "int", null);
            $this->isPager = true;
        } elseif ($request->get('page', "int", null) != null) {
            $this->suppliedOffset = ($request->get('page', "int", null) - 1) * $this->suppliedLimit;
            $this->isPager = true;
        }

        // Check if we pass the count parameter with whatever value
        if ($request->has('count')) {
            $this->isCount = true;
        }

        // http://jsonapi.org/format/#fetching
        $this->parseSearchParameters($request);
    }
1367832
public function send()
    {
        $this->sendHeaders();
        $this->sendContent();

        if (function_exists('fastcgi_finish_request')) {
            fastcgi_finish_request();
        } elseif ('cli' !== PHP_SAPI) {
            static::closeOutputBuffers(0, true);
        }

        return $this;
    }
660136
public function getRequest()
    {
        if ($this->hasRequest() === false) {
            // Try to get request from container.
            $this->setRequest($this->getContainer()->get('request_stack')->getCurrentRequest());
        }

        if ($this->hasRequest() === false) {
            throw new \RuntimeException("Sorry, the request is not available in this context");
        }

        return $this->request;
    }
877892
public function processRequest()
    {
        // get version cache file
        $version = $this->getVersion();

        // get class data from the compiled cache files
        $classData = $this->compilerCache->getCacheContent($this->api, $this->class, $version);

        // match request
        return $this->matchRequest($classData);
    }
1032133
public function send()
    {
        $arguments = func_get_args();
        $method    = array_shift($arguments);
        $args      = array_shift($arguments);

        foreach ($this as $helper) {
            $class = new ReflectionClass($helper);

            if ($class->hasMethod($method)) {
                return $class->getMethod($method)->invokeArgs($helper, $args);
            }
        }

        return parent::send($method);
    }
122485
public function dispatch() {

		$this->response = new stdClass();

		// blank headers
		$this->curl_headers = '';

		$start_time = microtime( true );

		// send request + save raw response body
		$this->response->body = curl_exec( $this->ch );

		// request duration
		$this->request->duration = round( microtime( true ) - $start_time, 5 );

		// response code
		$this->response->code = curl_getinfo( $this->ch, CURLINFO_HTTP_CODE );

		// response headers
		$this->response->headers = $this->get_response_headers();

		curl_close( $this->ch );

		$parsed_response = $this->get_parsed_response( $this->response->body );

		// check for invalid JSON
		if ( null === $parsed_response ) {

			throw new WC_API_Client_HTTP_Exception( sprintf( 'Invalid JSON returned for %s.', $this->request->url ), $this->response->code, $this->request, $this->response );
		}

		// any non-200/201/202 response code indicates an error
		if ( ! in_array( $this->response->code, array( '200', '201', '202' ) ) ) {

			// error message/code is nested sometimes
			if ( $this->json_decode_as_array ) {

				list( $error_message, $error_code ) = is_array( $parsed_response['errors'] ) ? array(
					$parsed_response['errors'][0]['message'],
					$parsed_response['errors'][0]['code']
				) : array(
					$parsed_response['errors']['message'],
					$parsed_response['errors']['code']
				);

			} else {

				list( $error_message, $error_code ) = is_array( $parsed_response->errors ) ? array(
					$parsed_response->errors[0]->message,
					$parsed_response->errors[0]->code
				) : array(
					$parsed_response->errors->message,
					$parsed_response->errors->code
				);
			}

			throw new WC_API_Client_HTTP_Exception( sprintf( 'Error: %s [%s]', $error_message, $error_code ), $this->response->code, $this->request, $this->response);
		}

		return $this->build_result( $parsed_response );
	}
988780
public function jsonSerialize(): stdClass
    {
        $object = (object)object_get_properties($this, $this instanceof DynamicEntity);

        /** @var Event\ToJson $event */
        $event = $this->dispatchEvent(new Event\ToJson($this, $object));
        $data = i\type_check($event->getPayload(), stdClass::class, new UnexpectedValueException());

        return $data;
    }
102013
public function server()
    {
        $this->prepareInput();

        $encryptStr = !empty($_GET['echostr']) ? $_GET['echostr'] : $this->encryptStr;

        $input = array(
            $encryptStr,
            $this->token,
            $this->input->get('timestamp'),
            $this->input->get('nonce'),
        );

        if ($this->input->get('msg_signature')
            && $this->signature($input) !== $this->input->get('msg_signature')
        ) {
            throw new Exception('Bad Request', 400);
        }

        if ($this->input->get('echostr')) {

            $xml = $this->getCrypt()->decrypt($this->input->get('echostr'), $this->appId);
            
            return strip_tags($xml);
        }

        return $this->response($this->handleRequest());

    }