private function processSetOpt()

in agent/php/ElasticApm/Impl/AutoInstrument/CurlHandleTracker.php [298:378]


    private function processSetOpt($optionId, Closure $getOptionValue): void
    {
        if (!$this->util->verifyIsInt($optionId)) {
            return;
        }

        switch ($optionId) {
            case CURLOPT_CUSTOMREQUEST:
                $optionValue = null;
                if (!$getOptionValue(/* ref */ $optionValue)) {
                    return;
                }
                if (!$this->util->verifyIsString($optionValue)) {
                    return;
                }
                /** @var string $optionValue */
                $this->httpMethod = $optionValue;
                break;

            case CURLOPT_HTTPHEADER:
                $optionValue = null;
                if (!$getOptionValue(/* ref */ $optionValue)) {
                    return;
                }
                if (!$this->util->verifyIsArray($optionValue)) {
                    return;
                }
                /** @var mixed[] $optionValue */
                $this->headersSetByApp = $optionValue;
                break;

            case CURLOPT_HTTPGET:
                // Based on https://github.com/curl/curl/blob/curl-7_73_0/lib/setopt.c#L841
                $this->httpMethod = self::GET_HTTP_METHOD;
                break;

            case CURLOPT_NOBODY:
                $optionValue = null;
                if (!$getOptionValue(/* ref */ $optionValue)) {
                    return;
                }
                // Based on https://github.com/curl/curl/blob/curl-7_73_0/lib/setopt.c#L269
                if ($optionValue) {
                    $this->httpMethod = self::HEAD_HTTP_METHOD;
                } elseif ($this->httpMethod === self::HEAD_HTTP_METHOD) {
                    $this->httpMethod = self::GET_HTTP_METHOD;
                }
                break;

            case CURLOPT_POST:
                // Based on https://github.com/curl/curl/blob/curl-7_73_0/lib/setopt.c#L616
                $optionValue = null;
                if (!$getOptionValue(/* ref */ $optionValue)) {
                    return;
                }
                $this->httpMethod = $optionValue ? self::POST_HTTP_METHOD : self::GET_HTTP_METHOD;
                break;

            case CURLOPT_POSTFIELDS:
                // Based on https://github.com/curl/curl/blob/curl-7_73_0/lib/setopt.c#L486
                $this->httpMethod = self::POST_HTTP_METHOD;
                break;

            case CURLOPT_PUT:
                // Based on https://github.com/curl/curl/blob/curl-7_73_0/lib/setopt.c#L292
                $optionValue = null;
                if (!$getOptionValue(/* ref */ $optionValue)) {
                    return;
                }
                $this->httpMethod = $optionValue ? self::PUT_HTTP_METHOD : self::GET_HTTP_METHOD;
                break;

            case CURLOPT_URL:
                $optionValue = null;
                if (!$getOptionValue(/* ref */ $optionValue)) {
                    return;
                }
                $this->setUrl($optionValue);
                break;
        }
    }