$data, 'response' => null ]; $params = [ 'http' => [ 'method' => strtoupper($method_type), 'content' => $data, 'header' => [ 'Content-type: application/json', 'Content-Length: '.strlen($data) ], // Fetches the content even on failure status codes. Necessary for correct SCIM response. 'ignore_errors' => '1' ] ]; if ($auth_token !== null) { $params['http']['header'][] = 'Authorization: Bearer '.$auth_token; } $handle = @fopen($url, 'rb', false, stream_context_create($params)); if ($handle) { $response = @stream_get_contents($handle); fclose($handle); } else { $php_errormsg = CTestArrayHelper::get(error_get_last(), 'message'); $response = false; } if ($response !== false) { $debug['response'] = $response; if ($response !== '') { $response = json_decode($response, true); if (!is_array($response)) { throw new Exception('API response is not in JSON format'); } } } else { static::$debug[] = $debug; throw new Exception('Problem with '.$url.', '.$php_errormsg); } static::$debug[] = $debug; return $response; } /** * Prepare request for SCIM API call and make SCIM API call (@see callRaw). * * @param string $method SCIM API method to be called. * @param array $params SCIM API call params. * * @return array */ public static function call($method, $params) { return static::callRaw([ 'method' => $method, 'params' => $params ], static::$token); } }