예제 #1
0
 public static function getServerResponse($url = null, $format = false, $onlyResponseCode = false, $checkIfSent = false)
 {
     if (!is_bool($checkIfSent)) {
         throw new \Exception('CheckIfSent parameter must be an boolean');
     }
     if (!is_bool($onlyResponseCode)) {
         throw new \Exception('onlyResponseCode parameter must be an boolean');
     }
     if ($onlyResponseCode) {
         return self::getHeaderResponseStatusCode();
     }
     if (is_null($url)) {
         $request = Http::getRootRequest();
         $url = Http::isHttps() ? 'https://' . $request : 'http://' . $request;
     }
     if (!Validate::isUrl($url)) {
         throw new \Exception('Url must be a valid url');
     }
     if (!is_bool($format)) {
         throw new \Exception('Format parameter must be an boolean');
     }
     $response = $checkIfSent ? headers_sent() ? get_headers($url, $format) : null : get_headers($url, $format);
     if (!$response && !$checkIfSent) {
         throw new \Exception('Error while get headers response status');
     }
     return $response;
 }