Sitemap, RSS and archive: one visibility policy for three readers
Shared content eligibility, different archive and feed windows, and exact comparisons of public identities.
A story has disappeared from the archive, yet its address remains in the sitemap. Or a scheduled article still cannot be opened on the website, while RSS already exposes its title. Each generator may work without an error on its own. The discrepancy arises because three readers answer the same question differently: which material may be shown now?
A shared visibility rule helps align those answers. It determines eligible material, while the archive, feed and sitemap choose their form and scope. A common policy does not require the first archive page and the complete sitemap to contain the same number of entries.
The independent PHP example with eleven synthetic records ran in one teaching Demo. The results check its shared visibility policy locally, without establishing actual indexing, feed delivery, or changes to a live website.
Visibility has an exact context
The request “give me published articles” hides several parameters. We need the site, exact locale, reading instant and intended audience. Material from one journal must not accidentally appear in another journal's sitemap, even when their local identifiers coincide. Having a Ukrainian text does not create a ready English page either.
Each row in the teaching catalogue represents one language version. It has a stable content ID, site, locale, state, audience, release time, modification time and slug. Only published material with a public audience enters the public set, for the requested site and locale, when release_at <= now. Draft, scheduled, withdrawn and private records fail that rule.
This is deliberately a small model. It accepts publication decisions as trusted input and does not implement the editorial workflow. The application owns site selection: an arbitrary request parameter must not be accepted without validation. Personal material would require a different access policy; it is entirely outside the eligible public results in this exercise.
Time opens a boundary without changing state
The time comparison is inclusive. A record released at instant T is absent one second before T and may enter the set exactly at T. The same instant expressed with another time-zone offset must produce the same answer. The fixture therefore stores explicit UTC values, and reading receives one externally supplied DateTimeImmutable.
An overdue scheduled state does not automatically become published. Reaching a date and successfully making a publication decision are different events. If a background worker has not performed that transition, all three consumers continue hiding the record. Another system may compute visibility without such a transition, but that choice must then be its single consistent contract.
Nor should a comparison read the current time independently three times. If the archive is built before a boundary and the sitemap afterwards, different sets may be correct. The exercise supplies all three representations with the same instant and the same immutable data snapshot. That provides a fair basis for local comparison, but does not yet establish consistency in a live database.
One list, different windows
After filtering, records are ordered by release time from newest to oldest. A stable ID resolves equal timestamps. Without that second criterion, an entry at a page boundary could move even when its content has not changed. We will represent the complete order in the initial context as B, C, A.
| Representation | Selected scope | Expected records |
|---|---|---|
| Archive, page 1 | First two | B, C |
| Archive, page 2 | Next two | A |
| RSS | Two latest publications | B, C |
| Sitemap for this locale | Entire eligible set | B, C, A |
Comparing the first page and complete sitemap as equal sets would be a mistake. The correct conditions differ: every result belongs to the shared eligible set; the union of every page from that same snapshot covers it without duplicates; and the capped feed contains the specified beginning of the order. For the small control dataset, we can also remove the limits and compare three complete representations.
Locale changes scope too. The exercise generates a sitemap for one locale, so it compares it with the archive and RSS in that same language. A sitemap covering every ready locale would naturally be larger. Such an extension requires an explicit union of contexts; an arbitrary language substitution is not a completed translation. With an empty set, the archive is empty, RSS retains its channel description, and the model emits no sitemap file; future integration must define the HTTP response for that case.
Identity survives an address change
Comparison needs a key containing the site, content ID and locale. A slug alone is unsuitable: it can change, and the same spelling on different sites does not identify the same publication. Even a correct entry count can conceal an error when one article is accidentally replaced by another.
One route owner generates the address from a validated slug and a trusted site registry. None of the three generators invents its own host from the current request. A future Symfony command must account for the absence of HTTP context: the routing documentation describes default_uri for generating correct absolute URLs. A multi-site application selects the context for each site explicitly.
In RSS, the model uses a stable guid and explicitly sets isPermaLink="false": identity does not have to be an address. The RSS 2.0 specification defines that distinction. Changing a slug updates the link while preserving the GUID. Conversely, two different identities claiming one canonical URL make generation fail; silently dropping a duplicate would conceal a contradiction in the source.
Format must not change the rules
In the example, VisibilitySnapshot selects records once, while Projections applies windows and serialization. HTML has no additional “convenient” route to drafts. RSS does not weaken the time check. The sitemap does not start reading every row merely because ordinary visitors do not see it.
HTML escapes the title, summary and attribute values. XML is assembled from elements and text nodes using DOMDocument::createTextNode, rather than concatenating a title between XML tags. The control text contains an ampersand, quotation marks and angle brackets: parsing must restore them as text without creating additional elements.
XML escaping alone does not define a feed client's rich-text policy. This exercise therefore sends a title, link, GUID and date, but adds no HTML item description. Full text or HTML summaries would require separately defined sanitization and display rules. A local XML parser does not establish how every external feed reader behaves.
The sitemap uses absolute URLs on one host, UTF-8 and appropriate XML escaping. Its lastmod comes from the page's modification, not the file's build time: the Sitemaps protocol explicitly makes that distinction. If an otherwise eligible record has a modification time later than the control instant, the model refuses generation. It does not conceal the contradiction by substituting now.
Withdrawal needs new data
A shared function cannot repair an outdated snapshot. After an article is withdrawn, a fresh selection must exclude it from all three representations. An object created from old data continues to contain the previous set. A prepared check intentionally shows both states, so immutability of a local object is not mistaken for cache invalidation.
Real generation needs a source revision or consistent snapshot, cache-update rules and a defined point after which withdrawal becomes visible to readers. In a large archive, inserting records during page traversal can also shift an offset. This exercise reads pages from a fixed set; cursors, transactional snapshots and concurrent updates remain a separate task.
The article's public route must apply current access rules regardless of its presence in discovery indexes. Removing a URL from a sitemap does not close the page, and removing an item from a new feed does not erase a copy already downloaded by someone else's client. Rules for finding material and obtaining its bytes must agree while retaining their own boundaries.
Expectations do not come from the same filter
If all three generators use one incorrect list, they can easily agree with each other. Before writing the PHP source, a separate file therefore froze expected keys, URLs and order for the synthetic data. The check compared output with that file, rather than making a fourth call to the same selector.
The initial dataset includes a draft, an overdue scheduled record, a future published record, withdrawn and private material, another site and another locale. Separate checks cover the exact time boundary, an explicit publication decision, withdrawal in a fresh snapshot, a slug change and GUID stability. A repeated identity, URL collision, unknown locale or invalid XML text must cause an explicit refusal.
The actual native run completed 19 scenarios with 56 assertions on PHP 8.5.12 and libxml 2.9.14; DOM/JSON were available. UK selection produced B,C,A, archive pages B,C and A, RSS with limit 2 produced B,C, and the sitemap for that locale produced B,C,A. All case names exactly matched the frozen oracle. Checks covered the inclusive time boundary, timezone-equivalent instant, explicit scheduled transition, withdrawal/new snapshot, site/locale, hidden sentinel refusal, HTML/XML text roundtrip, GUID after a slug change, duplicate/collision and invalid input refusal, empty scope, and windows. A separate PHPUnit adapter passed as 1 test with 8 assertions; it does not add another 19 distinct cases. The canonical suite requires PHP 8.4.1; other PHP versions were not run. This is one immutable array snapshot with zero network calls, without HTTP/DB/transaction/concurrency/cache/scheduler/file publication/XSD/indexing proof. An empty sitemap remains null; this example does not define its HTTP policy.
The practical value of this contract is an understandable reason for every difference. Older material may legitimately fall outside a short feed while remaining in the archive. A draft cannot enter the sitemap through another selection path. And a visibility change must have a verifiable path from the source decision to every public representation.