Wiring the sitemap command into an adapter¶
The command body, the reader and the check live here; an adapter parses its own input and binds three objects.
Everything reads one SitemapConfig, built from the raw sitemap block of the adapter's configuration.
use IndexNowKit\Sitemap\Check\SitemapSpoolCheck;
use IndexNowKit\Sitemap\Console\SitemapOptions;
use IndexNowKit\Sitemap\Console\SitemapRunner;
use IndexNowKit\Sitemap\SitemapConfig;
use IndexNowKit\Sitemap\SitemapReader;
$sitemap = SitemapConfig::fromArray($raw['sitemap'] ?? []); // throws ConfigurationException naming the key
$reader = SitemapReader::fromConfig($sitemap, $kit->transport ?? TransportFactory::lazy($kit->config), $logger);
$check = new SitemapSpoolCheck($sitemap); // add it to the checks of your `check` command
$runner = new SitemapRunner($kit, $reader, $submitterFactory, $sitemap->url, $formatter, sitemapUrlOption: 'myfw.sitemap.url');
$exit = $runner->run($io, new SitemapOptions($argument, $changedSince, $allowForeignHosts, $force, $dryRun, $json));
- Configuration. Add
SitemapConfig::OPTIONSto the keys yourAdapter\ConfigFactoryowns (ownedOptions: [...MY_OPTIONS, ...SitemapConfig::OPTIONS]), so a typo inside the block is warned about. Do not list a baresitemapkey: it would stopConfig::unknownOptions()from looking inside the block. At runtime build the block withSitemapConfig::loadOrDisabled($block, $logger, 'php artisan indexnow:check'): an invalid block is onecriticalline andSitemapConfig::disabled(), the way the coreConfigFactory::load()treats the core options (a DI container that validates at compile time, like the bundle, usesfromArray()and lets the build fail); whenenabledis false, register no command (bundle) or refuse to run it withsitemap.enabled is false.and exitINVALID(Laravel, Yii2). - Log lines. The one line the wiring above adds, so operators can grep for it (the core's
docs/operations.mdlists the rest):
| Level | Message |
|---|---|
critical |
indexnow: invalid sitemap configuration, the sitemap command is disabled until it is fixed: {error} (run "{check}") — loadOrDisabled(), {check} is the adapter's check command (Laravel, Yii2) |
- Transport. The reader fetches over the transport the facade submits through, so
http.clientandhttp.timeoutapply and nothing is discovered twice.$kit->transportisnullonly when the facade was built around a custom submitter;Http\TransportFactory::lazy($kit->config)covers that. - Source. Type the command against
SitemapSourceInterfaceand expose the reader under an alias of it, so an application can decorate the source (filter, rewrite) or replace it.--allow-foreign-hostsonly reaches the shippedSitemapReader; the runner warns when the configured source is something else. - Output. The runner streams, submits every
batch.max_urlsURLs throughAdapter\SubmitterFactory::choose()(--force/--dry-runget a separate submitter), folds results intoSubmission\ResultSummary, and submits the pending batch before reporting a mid-run failure;--jsonkeeps stdout machine-readable (the error goes to stderr). Exit codes areConsole\ExitCodeofindexnowkit/console. - Words. The only framework-specific string is
sitemapUrlOption, printed inGive a sitemap URL, or configure <option> or base_url.when no sitemap is known.
The reference wiring: IndexNowKitLoader of the Symfony bundle (services indexnowkit.sitemap_config,
indexnowkit.sitemap_reader, indexnowkit.console.sitemap), IndexNowKitServiceProvider::registerDiagnostics()
in Laravel, IndexNowComponent::sitemapConfig() / sitemapSource() in Yii2.