mirror of
https://github.com/cerbero90/json-parser.git
synced 2025-01-17 21:18:41 +01:00
Implement trait to detect endpoints
This commit is contained in:
parent
0f78f3c6e6
commit
820b485113
25
src/Concerns/DetectsEndpoints.php
Normal file
25
src/Concerns/DetectsEndpoints.php
Normal 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']);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user