Files

30 lines
874 B
PHP
Raw Permalink Normal View History

<?php
namespace AfFulltext;
final class FetchResult {
public function __construct(
public readonly string $html = '',
public readonly string $effective_url = '',
public readonly int $status = 0,
public readonly ?string $error = null,
) {}
public function ok(): bool {
return $this->error === null && $this->html !== '';
}
}
/**
* How a page's HTML is obtained. Kept behind an interface so the extraction
* pipeline is identical whether the markup came from a plain HTTP GET or from a
* headless browser -- and so the engine can be exercised from the CLI without
* tt-rss present.
*/
interface Fetcher {
/** @param array<string,string> $headers extra request headers (lowercased names) */
public function fetch(string $url, array $headers = []): FetchResult;
/** Short identifier used in logs and the prefs UI. */
public function name(): string;
}