lost-and-fonds / ticker-tape
A standalone RSS reader that preserves publisher data and reports uncertainty.
Requires
- php: ^8.3
- ext-dom: *
- ext-libxml: *
- ext-xmlreader: *
- lib-libxml: >=2.9.14
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-11-30 22:52:40 UTC
README
Read faithfully. Write correctly.
Ticker Tape is a standalone PHP library for reading RSS 2.0 feeds without silently rewriting what publishers said. It separates each field's source text, interpreted value, validity, and diagnostics, so ordinary feeds are pleasant to work with and irregular feeds remain understandable.
use TickerTape\Feed; $feed = Feed::parse($xml); echo $feed->title->value; foreach ($feed->items as $item) { echo $item->title->value ?? '(untitled item)'; if ($item->publishedAt->isValid()) { echo $item->publishedAt->value->format(DATE_ATOM); } }
Installation
composer require lost-and-fonds/ticker-tape
Requires PHP 8.3 or newer, the DOM, XMLReader, and libxml extensions, and a security-patched libxml 2.9.14 or newer.
Why Ticker Tape?
Traditional feed readers often give you a convenient interpretation and hide the irregularities underneath it. Ticker Tape makes that interpretation explicit:
- Observe rather than guess. Every interpreted field has
raw,value,validity, andissues. - Never invent missing facts. Missing GUIDs stay missing, impossible dates stay invalid, and unspecified timezones are not silently supplied.
- Preserve source structure. Inspect duplicate fields, repeated enclosures, unfamiliar namespaces, extension attributes, and mixed XML content.
- Use a small API. Call
Feed::parse($xml)and iterate$feed->items. No service container or framework integration required. - Report useful diagnostics. Machine-readable issue codes, severities, and source locations explain why something could not be interpreted.
- Parse untrusted XML defensively. External entities and DTDs are rejected, with input and parser resource limits.
Ticker Tape interprets feed data; it does not fetch feeds, download enclosures, deduplicate entries, repair content, or make application-specific editorial decisions.
Reading a feed
Pass a string containing RSS XML to Feed::parse(). The caller controls how that XML is obtained.
use TickerTape\Feed; use TickerTape\ParseException; try { $feed = Feed::parse($xml); } catch (ParseException $exception) { foreach ($exception->issues as $issue) { echo "{$issue->code}: {$issue->message}\n"; } throw $exception; } echo $feed->title->value ?? '(untitled feed)'; foreach ($feed->items as $item) { echo $item->title->value ?? $item->description->value ?? '(untitled item)'; }
Malformed XML, an unsupported feed format, or an unusable RSS envelope causes a ParseException. A malformed individual field normally does not: its observation explains the problem while the rest of the feed remains accessible.
Inspecting an observed value
use TickerTape\Validity; $date = $item->publishedAt; $date->raw; // XML-decoded publisher text, e.g. "Tue, 32 Nov 2026 10:00:00 GMT" $date->value; // null when there is no defensible interpretation $date->validity; // Validity::Invalid $date->issues; // list of Issue objects explaining the problem if ($date->isValid()) { // PHPStan narrows the value to DateTimeImmutable here. echo $date->value->format(DATE_ATOM); }
Validity has five cases:
| Case | Meaning |
|---|---|
Valid |
One supported interpretation exists; value is non-null. |
Invalid |
The supplied value fails the applicable rules. |
Ambiguous |
There is no single defensible interpretation. |
Unsupported |
The supplied representation is not supported by the reader. |
Absent |
The field was not supplied. This is not automatically an error. |
A Valid observation can still carry warnings, for example when the written weekday disagrees with the calendar date. isValid() is also annotated for PHPStan's generic type narrowing.
raw preserves XML-parsed text or attribute content, not necessarily the original byte-for-byte XML spelling. If your application needs exact bytes, retain the original input.
Items and enclosures
$feed->items is repeatably iterable. Entry objects are interpreted lazily as you traverse it; starting another iteration works, including after a partial traversal.
foreach ($feed->items as $item) { echo $item->guid->value ?? '(no GUID)'; foreach ($item->enclosures as $enclosure) { echo $enclosure->url->value ?? '(no URL)'; echo $enclosure->length->value ?? '(unknown bytes)'; echo $enclosure->type->value ?? '(unknown type)'; } }
Enclosure URLs, byte lengths and media types are publisher declarations, not verified attributes of downloaded media. The reader does not issue network requests.
The initial RSS reader exposes common channel and entry fields, categories, enclosures, publication dates, and content:encoded independently of description. Other source fields remain accessible through the source view.
Duplicates and XML extensions
If a nominally single-valued field occurs more than once, its interpreted observation is Ambiguous. Ticker Tape does not quietly select the first or last occurrence. Every occurrence is available in source order:
foreach ($item->source->elements('guid') as $guidElement) { echo $guidElement->text(); } // Look up a namespaced extension by local name and namespace URI. $mediaGroups = $item->source->elements( 'group', 'http://search.yahoo.com/mrss/', ); foreach ($mediaGroups as $group) { foreach ($group->children() as $child) { // SourceElement or SourcePart: inspect structure without losing it. } }
The read-only source view exposes namespace URIs and prefixes, attributes, child elements, text, CDATA, comments, and processing instructions. It does not expose mutable DOM nodes.
Diagnostics
An issue has a stable code, severity, human-readable message, and location (a source path or XML parser line/column when available).
foreach ($feed->issues as $issue) { echo $issue->code . ' at ' . ($issue->location->path ?? '(document)') . "\n"; } foreach ($feed->items as $item) { foreach ($item->publishedAt->issues as $issue) { echo $issue->code . ': ' . $issue->message . "\n"; } }
Diagnostics are scoped: $feed->issues contains feed-level findings; $item->issues contains item-level findings; field observations carry their own issues. Visiting items does not mutate the feed's issue list or secretly aggregate unvisited items.
Design boundaries
Ticker Tape reads RSS 2.0. Atom parsing and RSS/Atom writing are separate future capabilities. Reading does not imply transforming, fixing, republishing or resyndicating a feed.
The parser accepts an XML string and performs no automatic fetching. It rejects DTDs and external entities and enforces document limits. All returned publisher strings remain untrusted input: applications are responsible for escaping rendered HTML and applying transport and security policies before using any referenced URI.
For precise interpretation rules, error semantics and source-fidelity guarantees, see the v0.1 design contract.
Development
Install dependencies and run the tests and static analysis:
composer install
composer test
composer analyse
The XML security test suite uses a loopback socket. CI validates Composer and runs PHPUnit, PHPStan and a memory check against PHP 8.3 with patched libxml 2.9.14 and a modern PHP/libxml combination.
The feed pathology corpus documents the synthetic regression inputs, their historical evidence, and the expected source and interpretation behavior.
To reproduce the minimum-runtime checks using Docker, run from the repository root:
docker run --rm --network none \
--volume "$PWD:/app:ro" --workdir /app \
php:8.3-cli-bookworm sh tests/check-platform.sh minimum
Use php:8.5-cli-alpine and modern for the modern lane, or run equivalent containers under Podman.
License
Ticker Tape is available under the MIT License.