Implement trait to detect endpoints

This commit is contained in:
Andrea Marco Sartori 2022-10-29 17:02:41 +10:00
parent 0f78f3c6e6
commit 820b485113

View File

@ -0,0 +1,25 @@
<?php
namespace Cerbero\JsonParser\Concerns;
/**
* The trait to detect endpoints.
*
*/
trait DetectsEndpoints
{
/**
* Determine whether the given string points to an endpoint
*
* @param string $string
* @return bool
*/
public function isEndpoint(string $string): bool
{
if (($url = parse_url($string)) === false) {
return false;
}
return in_array($url['scheme'] ?? null, ['http', 'https']) && isset($url['host']);
}
}