You are here

public static function Utility::parseUrl in Rocket.Chat 8

Same name and namespace in other branches
  1. 8.2 src/Utility.php \Drupal\rocket_chat\Utility::parseUrl()

Helper function to split an URL into its base components.

Parameters

string $url: Url to parse.

Return value

array Url in its separated Parts.

Throws

\HttpUrlException Throws when scheme is missing.

1 call to Utility::parseUrl()
Utility::serverRun in src/Utility.php
ServerRun.

File

src/Utility.php, line 73
Contains \Drupal\rocket_chat\FormManager.

Class

Utility
Check the form values.

Namespace

Drupal\rocket_chat

Code

public static function parseUrl($url) {
  $returnValue = parse_url($url);
  if (!isset($returnValue['scheme'])) {
    throw new \HttpUrlException("Missing Scheme.", 404);
  }
  if (!isset($returnValue['host'])) {
    $returnValue['hosts'] = 'localhost';
  }
  if (!isset($returnValue['path'])) {
    $returnValue['path'] = "";
  }
  if (!isset($returnValue['port'])) {
    switch ($returnValue['scheme']) {
      case "http":
        $returnValue['port'] = 80;
        break;
      case "https":
        $returnValue['port'] = 443;
        break;
    }
  }
  $returnValue['baseUrl'] = $returnValue['host'] . $returnValue['path'];
  switch ($returnValue['scheme']) {
    default:
      $returnValue['url'] = "tcp://" . $returnValue['baseUrl'];
      break;
    case "https":
      $returnValue['url'] = "tls://" . $returnValue['baseUrl'];
      break;
  }
  return $returnValue;
}