mirror of
https://github.com/YGGverse/parser-php.git
synced 2026-03-31 17:25:28 +00:00
add URN parser
This commit is contained in:
parent
f5b1beb51e
commit
5e1003cca2
1 changed files with 39 additions and 0 deletions
39
src/Urn.php
Normal file
39
src/Urn.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue