class Utility in Rocket.Chat 8
Same name and namespace in other branches
- 8.2 src/Utility.php \Drupal\rocket_chat\Utility
Check the form values.
Hierarchy
- class \Drupal\rocket_chat\Utility
Expanded class hierarchy of Utility
1 file declares its use of Utility
File
- src/
Utility.php, line 33 - Contains \Drupal\rocket_chat\FormManager.
Namespace
Drupal\rocket_chatView source
class Utility {
/**
* ServerRun.
*
* @param string $url
* Url to use.
*
* @return bool
* Connection Worked?
*/
public static function serverRun($url) {
$urlSplit = Utility::parseUrl($url);
try {
if ($ping = fsockopen($urlSplit['url'], $urlSplit['port'], $errCode, $errStr, 10)) {
fclose($ping);
return TRUE;
}
else {
return FALSE;
}
} catch (\Exception $exception) {
error_log("serverRun encountered and exception, check [{$url}] for valid URL");
return FALSE;
}
}
/**
* Helper function to split an URL into its base components.
*
* @param string $url
* Url to parse.
*
* @return array
* Url in its separated Parts.
*
* @throws \HttpUrlException
* Throws when scheme is missing.
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Utility:: |
public static | function | Helper function to split an URL into its base components. | |
Utility:: |
public static | function | ServerRun. |