add URN parser

This commit is contained in:
ghost 2023-08-26 21:28:13 +03:00
parent f5b1beb51e
commit 5e1003cca2

39
src/Urn.php Normal file
View file

@ -0,0 +1,39 @@
<?php
namespace YGGverse\Parser;
class Urn {
public static function is(string $urn) : bool
{
return ('urn' == parse_url($urn, PHP_URL_SCHEME));
}
public static function parse(string $urn) : mixed
{
if (!self::is($urn))
{
return false;
}
if ($part = explode(':', $urn))
{
if (empty($part[0]) || empty($part[1]) || empty($part[2]))
{
return false;
}
unset($part[0]);
$result =
[
'urn' => implode(':', $part),
'parts' => $part,
];
return (object) $result;
}
return false;
}
}