Search by

adachsoft / web-content-fetch-contract

Arkadiusz Adach

Provider-agnostic SPI contracts and exceptions for fetching and extracting web content from URLs in PHP.

Package info

gitlab.com/a.adach/web-content-fetch-contract

Issues

pkg:composer/adachsoft/web-content-fetch-contract

Statistics

Installs: 14

Dependents: 1

Suggesters: 0

Stars: 0

v0.1.0 2026-09-28 13:13 UTC

This package is auto-updated.

Last update: 2026-09-28 11:14:41 UTC


README

A provider-agnostic PHP contract for fetching and extracting textual content from web pages.

Purpose

This package defines a stable service provider interface (SPI) that keeps application code independent from the HTTP client, browser automation tool, DOM parser, readability engine, or AI reader used to retrieve web content.

Features

  • A small WebContentFetcherInterface for URL-based content extraction.
  • Provider-specific options without coupling consumers to a concrete implementation.
  • A dedicated exception hierarchy for invalid URLs, unsupported options, and fetch failures.
  • PSR-4 autoloading and no runtime dependencies beyond PHP.

Installation

composer require adachsoft/web-content-fetch-contract

Integration

Implement the interface in an adapter package and inject that adapter into the application service that needs web content:

use AdachSoft\WebContentFetchContract\WebContentFetcherInterface;

final class ArticleReader
{
    public function __construct(
        private readonly WebContentFetcherInterface $contentFetcher,
    ) {
    }

    public function read(string $url): string
    {
        return $this->contentFetcher->fetchContent($url);
    }
}

Provider-specific options can be passed as an associative array:

$content = $contentFetcher->fetchContent(
    'https://example.com/article',
    ['timeout' => 10],
);

Catch ContentFetchExceptionInterface when the application needs one handler for all contract-level failures, or catch the specialized exceptions for more granular error handling.

See docs/examples/basic-usage.md for a complete adapter example.