Skip to content

Commit

Permalink
Introduce ISO-15924 Scripts (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
PrinsFrank authored Oct 8, 2023
1 parent 64ceb8d commit 77bbb17
Show file tree
Hide file tree
Showing 30 changed files with 1,269 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 200
max_line_length = 300
eclint_block_comment_start = /*
eclint_block_comment = *
eclint_block_comment_end = */
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/update-spec-scripts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Daily Scripts spec update

on:
workflow_dispatch:
schedule:
- cron: '55 17 * * *'

jobs:
update-specs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: composer install
- name: Run standard update command
run: composer update-spec -- --type=script
- name: Run CSFixer
run: composer cs:fix
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v4
with:
commit-message: Automatic Scripts spec update from upstream changes
delete-branch: true
title: 'Automatic Scripts spec update'
branch: update-spec/scripts
body: |
This PR makes sure the content of this package is updated with upstream changes in the specs.
labels: |
spec-update
automated pr
reviewers: prinsfrank
2 changes: 1 addition & 1 deletion dev/DataSource/Country/CountryAlpha2Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function transformName(string $key): ?string
return $key;
}

public static function transformValue(string $value): string|int|null
public static function transformValue(string $value, ?string $key): string|int|null
{
return $value;
}
Expand Down
2 changes: 1 addition & 1 deletion dev/DataSource/Country/CountryAlpha3Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function transformName(string $key): ?string
return $key;
}

public static function transformValue(string $value): string|int|null
public static function transformValue(string $value, ?string $key): string|int|null
{
return $value;
}
Expand Down
2 changes: 1 addition & 1 deletion dev/DataSource/Country/CountryNameSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function transformName(string $key): ?string
return $key;
}

public static function transformValue(string $value): string|int|null
public static function transformValue(string $value, ?string $key): string|int|null
{
return $value;
}
Expand Down
2 changes: 1 addition & 1 deletion dev/DataSource/Country/CountryNumericSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function transformName(string $key): ?string
return $key;
}

public static function transformValue(string $value): string|int|null
public static function transformValue(string $value, ?string $key): string|int|null
{
return $value;
}
Expand Down
2 changes: 1 addition & 1 deletion dev/DataSource/Currency/CurrencyAlpha3Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function transformName(string $key): ?string
return $key;
}

public static function transformValue(string $value): string|int|null
public static function transformValue(string $value, ?string $key): string|int|null
{
return $value;
}
Expand Down
2 changes: 1 addition & 1 deletion dev/DataSource/Currency/CurrencyNameSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function transformName(string $key): ?string
return $key;
}

public static function transformValue(string $value): string|int|null
public static function transformValue(string $value, ?string $key): string|int|null
{
return $value;
}
Expand Down
2 changes: 1 addition & 1 deletion dev/DataSource/Currency/CurrencyNumericSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function transformName(string $key): ?string
return $key;
}

public static function transformValue(string $value): string|int|null
public static function transformValue(string $value, ?string $key): string|int|null
{
return $value;
}
Expand Down
2 changes: 1 addition & 1 deletion dev/DataSource/DataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface DataSource
{
public static function transformName(string $key): ?string;

public static function transformValue(string $value): string|int|null;
public static function transformValue(string $value, ?string $key): string|int|null;

/** @return class-string<\BackedEnum> */
public static function getSpecFQN(): string;
Expand Down
2 changes: 1 addition & 1 deletion dev/DataSource/Http/HttpMethodSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static function ($matches) {
);
}

public static function transformValue(string $value): string|int|null
public static function transformValue(string $value, ?string $key): string|int|null
{
return $value;
}
Expand Down
2 changes: 1 addition & 1 deletion dev/DataSource/Http/HttpStatusCodeSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function transformName(string $key): ?string
return $key;
}

public static function transformValue(string $value): string|int|null
public static function transformValue(string $value, ?string $key): string|int|null
{
if (str_contains($value, '-')) {
return null; // Don't include reserved ranges in spec
Expand Down
2 changes: 1 addition & 1 deletion dev/DataSource/Language/LanguageAlpha2Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function transformName(string $key): ?string
return $key;
}

public static function transformValue(string $value): string|int|null
public static function transformValue(string $value, ?string $key): string|int|null
{
return strtolower(str_replace(' ', '', trim($value)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function transformName(string $key): ?string
return $key;
}

public static function transformValue(string $value): string|int|null
public static function transformValue(string $value, ?string $key): string|int|null
{
$bibliographicMarkerPos = strpos($value, '(B)');
if ($bibliographicMarkerPos === false) {
Expand Down
2 changes: 1 addition & 1 deletion dev/DataSource/Language/LanguageAlpha3CommonSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function transformName(string $key): ?string
return $key;
}

public static function transformValue(string $value): string|int|null
public static function transformValue(string $value, ?string $key): string|int|null
{
if (str_contains($value, '(T)') || str_contains($value, '(B)') || str_contains($value, '-')) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function transformName(string $key): ?string
return $key;
}

public static function transformValue(string $value): string|int|null
public static function transformValue(string $value, ?string $key): string|int|null
{
$terminologyMarkerPos = strpos($value, '(T)');
if ($terminologyMarkerPos === false) {
Expand Down
2 changes: 1 addition & 1 deletion dev/DataSource/Language/LanguageNameSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function transformName(string $key): ?string
return $key;
}

public static function transformValue(string $value): string|int|null
public static function transformValue(string $value, ?string $key): string|int|null
{
if (str_contains($value, 'Reserved')) {
return null;
Expand Down
67 changes: 67 additions & 0 deletions dev/DataSource/Script/ScriptAliasSource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
declare(strict_types=1);

namespace PrinsFrank\Standards\Dev\DataSource\Script;

use PrinsFrank\Standards\Dev\DataSource\HtmlDataSource;
use PrinsFrank\Standards\Scripts\ScriptAlias;
use PrinsFrank\Standards\Scripts\ScriptName;
use Symfony\Component\Panther\Client;
use Symfony\Component\Panther\DomCrawler\Crawler;

class ScriptAliasSource implements HtmlDataSource
{
public static function url(): string
{
return 'https://www.unicode.org/iso15924/iso15924-codes.html';
}

public static function xPathIdentifierKey(): string
{
return self::xPathIdentifierName();
}

public static function xPathIdentifierName(): string
{
return '//table[@class="simple"]/tbody/tr/td[3]';
}

public static function xPathIdentifierValue(): string
{
return '//table[@class="simple"]/tbody/tr/td[5]';
}

public static function transformName(string $key): ?string
{
return preg_replace('/_+/', '_', str_replace('+', '_', preg_replace('/\p{No}/u', '', $key) ?? ''));
}

public static function transformValue(string $value, ?string $key): string|int|null
{
$value = str_replace(' ', '', trim($value));
if ($value === '' || $key === 'Khutsuri_Asomtavruli_and_Nuskhuri') {
return null;
}

return $value;
}

public static function getSpecFQN(): string
{
return ScriptAlias::class;
}

public static function getKeyEnumFQN(): string
{
return ScriptName::class;
}

public static function afterPageLoad(Client $client, Crawler $crawler): void
{
}

public static function sort(): bool
{
return true;
}
}
62 changes: 62 additions & 0 deletions dev/DataSource/Script/ScriptCodeSource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);

namespace PrinsFrank\Standards\Dev\DataSource\Script;

use PrinsFrank\Standards\Dev\DataSource\HtmlDataSource;
use PrinsFrank\Standards\Scripts\ScriptCode;
use PrinsFrank\Standards\Scripts\ScriptName;
use Symfony\Component\Panther\Client;
use Symfony\Component\Panther\DomCrawler\Crawler;

class ScriptCodeSource implements HtmlDataSource
{
public static function url(): string
{
return 'https://www.unicode.org/iso15924/iso15924-codes.html';
}

public static function xPathIdentifierKey(): string
{
return self::xPathIdentifierName();
}

public static function xPathIdentifierName(): string
{
return '//table[@class="simple"]/tbody/tr/td[3]';
}

public static function xPathIdentifierValue(): string
{
return '//table[@class="simple"]/tbody/tr/td[2]';
}

public static function transformName(string $key): ?string
{
return preg_replace('/_+/', '_', str_replace('+', '_', preg_replace('/\p{No}/u', '', $key) ?? ''));
}

public static function transformValue(string $value, ?string $key): string|int|null
{
return str_replace(' ', '', trim($value));
}

public static function getSpecFQN(): string
{
return ScriptCode::class;
}

public static function getKeyEnumFQN(): string
{
return ScriptName::class;
}

public static function afterPageLoad(Client $client, Crawler $crawler): void
{
}

public static function sort(): bool
{
return true;
}
}
61 changes: 61 additions & 0 deletions dev/DataSource/Script/ScriptNameSource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);

namespace PrinsFrank\Standards\Dev\DataSource\Script;

use PrinsFrank\Standards\Dev\DataSource\HtmlDataSource;
use PrinsFrank\Standards\Scripts\ScriptName;
use Symfony\Component\Panther\Client;
use Symfony\Component\Panther\DomCrawler\Crawler;

class ScriptNameSource implements HtmlDataSource
{
public static function url(): string
{
return 'https://www.unicode.org/iso15924/iso15924-codes.html';
}

public static function xPathIdentifierKey(): string
{
return '//table[@class="simple"]/tbody/tr/td[1]';
}

public static function xPathIdentifierName(): string
{
return '//table[@class="simple"]/tbody/tr/td[3]';
}

public static function xPathIdentifierValue(): string
{
return '//table[@class="simple"]/tbody/tr/td[3]';
}

public static function transformName(string $key): ?string
{
return preg_replace('/_+/', '_', str_replace('+', '_', preg_replace('/\p{No}/u', '', $key) ?? ''));
}

public static function transformValue(string $value, ?string $key): string|int|null
{
return str_replace(' ', '', trim($value));
}

public static function getSpecFQN(): string
{
return ScriptName::class;
}

public static function getKeyEnumFQN(): string
{
return self::getSpecFQN();
}

public static function afterPageLoad(Client $client, Crawler $crawler): void
{
}

public static function sort(): bool
{
return true;
}
}
Loading

0 comments on commit 77bbb17

Please sign in to comment.