-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add source for automatic HTTP method update
- Loading branch information
1 parent
3d74a87
commit 2112f34
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters