Skip to content

Commit f5b4ae3

Browse files
authored
Add URI Schemes (#301)
1 parent 82225db commit f5b4ae3

File tree

9 files changed

+1360
-1
lines changed

9 files changed

+1360
-1
lines changed

.github/workflows/specs-regeneration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
- "php-regex-script"
3232
- "scripts"
3333
- "tld"
34+
- "uri-scheme"
3435
steps:
3536
- name: Checkout code
3637
uses: actions/checkout@v4
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Daily URI Scheme update
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '55 17 * * *'
7+
8+
env:
9+
GH_TOKEN: ${{ github.token }}
10+
11+
jobs:
12+
update-specs:
13+
uses: ./.github/workflows/reusable-update-spec.yml
14+
with:
15+
type: uri-scheme

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
"update-spec-language-subtag": "@update-spec PrinsFrank\\Standards\\Dev\\DataSource\\Mapping\\LanguageSubTagMapping",
5353
"update-spec-php-regex-script": "@update-spec PrinsFrank\\Standards\\Dev\\DataSource\\Mapping\\PHPRegexSupportedScriptsMapping",
5454
"update-spec-scripts": "@update-spec PrinsFrank\\Standards\\Dev\\DataSource\\Mapping\\ScriptMapping",
55-
"update-spec-tld": "@update-spec PrinsFrank\\Standards\\Dev\\DataSource\\Mapping\\TopLevelDomainMapping"
55+
"update-spec-tld": "@update-spec PrinsFrank\\Standards\\Dev\\DataSource\\Mapping\\TopLevelDomainMapping",
56+
"update-spec-uri-scheme": "@update-spec PrinsFrank\\Standards\\Dev\\DataSource\\Mapping\\URISchemeMapping"
5657
},
5758
"extra": {
5859
"branch-alias": {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace PrinsFrank\Standards\Dev\DataSource\Mapping;
4+
5+
use Facebook\WebDriver\WebDriverBy;
6+
use PrinsFrank\Standards\Dev\DataSource\Sorting\KeySorting;
7+
use PrinsFrank\Standards\Dev\DataTarget\EnumCase;
8+
use PrinsFrank\Standards\Dev\DataTarget\EnumCaseAttribute;
9+
use PrinsFrank\Standards\Dev\DataTarget\SpecFile;
10+
use PrinsFrank\Standards\URIScheme\Attributes\Status;
11+
use PrinsFrank\Standards\URIScheme\URIScheme;
12+
use PrinsFrank\Standards\URIScheme\URISchemeStatus;
13+
use RuntimeException;
14+
use stdClass;
15+
use Symfony\Component\Panther\Client;
16+
use Symfony\Component\Panther\DomCrawler\Crawler;
17+
use TypeError;
18+
use ValueError;
19+
20+
/**
21+
* @template TDataSet of object{name: string, template: string, description: string, status: string, wellKnown: string, reference: string, notes: string}&stdClass
22+
* @implements Mapping<TDataSet>
23+
*/
24+
class URISchemeMapping implements Mapping {
25+
public static function url(): string {
26+
return 'https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml';
27+
}
28+
29+
/**
30+
* @throws RuntimeException
31+
* @return list<TDataSet>
32+
*/
33+
public static function toDataSet(Client $client, Crawler $crawler): array {
34+
$dataSet = [];
35+
foreach ($crawler->filterXPath('//table[@id="table-uri-schemes-1"]/tbody/tr')->getIterator() as $item) {
36+
$columns = $item->findElements(WebDriverBy::xpath('./td'));
37+
if ($columns === []) {
38+
continue;
39+
}
40+
41+
if (array_key_exists(0, $columns) === false
42+
|| array_key_exists(1, $columns) === false
43+
|| array_key_exists(2, $columns) === false
44+
|| array_key_exists(3, $columns) === false
45+
|| array_key_exists(4, $columns) === false
46+
|| array_key_exists(5, $columns) === false
47+
|| array_key_exists(6, $columns) === false) {
48+
throw new RuntimeException('Expected exactly 7 columns');
49+
}
50+
51+
$record = (object) [];
52+
$record->name = $columns[0]->getText();
53+
$record->template = $columns[1]->getText();
54+
$record->description = $columns[2]->getText();
55+
$record->status = $columns[3]->getText();
56+
$record->wellKnown = $columns[4]->getText();
57+
$record->reference = $columns[5]->getText();
58+
$record->notes = $columns[6]->getText();
59+
60+
/** @var TDataSet $record */
61+
$dataSet[] = $record;
62+
}
63+
64+
return $dataSet;
65+
}
66+
67+
/**
68+
* @param list<TDataSet> $dataSet
69+
* @throws TypeError|ValueError
70+
* @return array<SpecFile>
71+
*/
72+
public static function toEnumMapping(array $dataSet): array {
73+
$URIScheme = new SpecFile(URIScheme::class, KeySorting::class);
74+
foreach ($dataSet as $dataRow) {
75+
$URIScheme->addCase(new EnumCase($dataRow->name, $dataRow->name, [new EnumCaseAttribute(Status::class, [URISchemeStatus::from($dataRow->status)])]));
76+
}
77+
78+
return [$URIScheme];
79+
}
80+
}

src/URIScheme/Attributes/Status.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace PrinsFrank\Standards\URIScheme\Attributes;
4+
5+
use Attribute;
6+
use PrinsFrank\Standards\URIScheme\URISchemeStatus;
7+
8+
#[Attribute]
9+
class Status {
10+
public function __construct(
11+
public readonly URISchemeStatus $status,
12+
) {
13+
}
14+
}

0 commit comments

Comments
 (0)