Skip to content

Commit

Permalink
Add source for automatic HTTP method update
Browse files Browse the repository at this point in the history
  • Loading branch information
PrinsFrank committed Nov 26, 2022
1 parent 3d74a87 commit 2112f34
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
66 changes: 66 additions & 0 deletions dev/DataSource/Http/HttpMethodSource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);

namespace PrinsFrank\Standards\Dev\DataSource\Http;

use PrinsFrank\Standards\Dev\DataSource\HtmlDataSource;
use PrinsFrank\Standards\Http\HttpMethod;
use Symfony\Component\Panther\Client;
use Symfony\Component\Panther\DomCrawler\Crawler;

class HttpMethodSource implements HtmlDataSource
{
public static function transformName(string $key): ?string
{
if ($key === '*' || $key === '') {
return null; // According to https://www.rfc-editor.org/rfc/rfc9110.html#name-method-registration, section 18.2, this is a reserved method
}

return $key;
}

public static function transformValue(string $value): string|int|null
{
return $value;
}

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

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

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

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

public static function xPathIdentifierName(): string
{
return '//table[@id="table-methods"]/tbody/tr/td[1]';
}

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

public static function url(): string
{
return 'https://www.iana.org/assignments/http-methods/http-methods.xhtml';
}

public static function afterPageLoad(Client $client, Crawler $crawler): void
{
$client->waitForElementToContain('//table/thead', 'Method Name');
}
}
2 changes: 2 additions & 0 deletions dev/SpecUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PrinsFrank\Standards\Dev\DataSource\Currency\ISO4217_Numeric_Source;
use PrinsFrank\Standards\Dev\DataSource\DataSource;
use PrinsFrank\Standards\Dev\DataSource\HtmlDataSource;
use PrinsFrank\Standards\Dev\DataSource\Http\HttpMethodSource;
use PrinsFrank\Standards\Dev\DataSource\Http\HttpStatusCodeSource;
use PrinsFrank\Standards\Dev\DataSource\Language\ISO639_1_Alpha_2_Source;
use PrinsFrank\Standards\Dev\DataSource\Language\ISO639_2_Alpha_3_Bibliographic_Source;
Expand Down Expand Up @@ -50,6 +51,7 @@ class SpecUpdater
/** @var array<class-string<DataSource>> */
public const HTTP_SOURCES = [
HttpStatusCodeSource::class,
HttpMethodSource::class,
];

/** @var array<class-string<DataSource>> */
Expand Down

0 comments on commit 2112f34

Please sign in to comment.