CoolCMS API

SitemapUrlsetWriter
in package

FinalYes

Writes one sitemap `<urlset>` file with hreflang alternatives, streaming.

Each entry is flushed to the file right after it is written, so memory holds only the entry in progress. The output is formatted with a two-space indent and an empty document is <urlset/>.

The byte count reflects what was actually written; SitemapBucketWriter uses it to guard the protocol limit of 50 MB.

Table of Contents

Constants

NS_SITEMAP  : mixed = 'http://www.sitemaps.org/schemas/sitemap/0.9'
NS_XHTML  : mixed = 'http://www.w3.org/1999/xhtml'

Properties

$buffer  : string
$byteCount  : int
$closed  : bool
$handle  : resource|null
$urlCount  : int
$xml  : XMLWriter

Methods

addEntry()  : void
Writes one entry: a `<url>` per language version, each linking to all versions.
close()  : string
Closes the document; returns the whole XML for in-memory output and an empty string for a file.
discard()  : void
Closes the file without finishing the document (after an error; the caller removes the temporary file).
getByteCount()  : int
Returns the bytes already written (for a file, actually sent to the file).
getUrlCount()  : int
toFile()  : self
toMemory()  : self
__construct()  : mixed
drain()  : void

Constants

Properties

$handle

private resource|null $handle

target file; null means in-memory output (returned by close())

Methods

addEntry()

Writes one entry: a `<url>` per language version, each linking to all versions.

public addEntry(array<string, string> $urlsByLocale, array{changefreq?: ?string, priority?: ?string, lastmod?: ?string} $meta) : void
Parameters
$urlsByLocale : array<string, string>

locale key => absolute URL

$meta : array{changefreq?: ?string, priority?: ?string, lastmod?: ?string}

close()

Closes the document; returns the whole XML for in-memory output and an empty string for a file.

public close() : string
Tags
throws
RuntimeException

when the final write or closing of the file fails

Return values
string

discard()

Closes the file without finishing the document (after an error; the caller removes the temporary file).

public discard() : void

getByteCount()

Returns the bytes already written (for a file, actually sent to the file).

public getByteCount() : int
Return values
int

toFile()

public static toFile(string $path) : self
Parameters
$path : string
Tags
throws
RuntimeException

when the file cannot be opened

Return values
self

__construct()

private __construct(resource|null $handle) : mixed
Parameters
$handle : resource|null
On this page

Search results