Download the PHP package netglue/sitemap-builder without Composer

On this page you can find all versions of the php package netglue/sitemap-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sitemap-builder

Another Sitemap Builder Utility in PHP

Why?

It's pretty easy to make an XML sitemap and there's lots of utilities out there, but these tend to concentrate on persisting the xml to disk. If you're running your app on a handful of servers, disks are a pain in the ass.

I wanted something that only generated the XML as a string so that I could easily throw that at a cache, or serialise to files on AWS or Google cloud or whatever.

Install

Install with composer in the normal way…

composer require netglue/sitemap-builder

This lib requires the xml writer extension, and a minimum of PHP 7.1

Tests

Coverage is currently 100%, just CD to the project directory and…

$ composer install
$ vendor/bin/phpunit

Usage

Single, standalone sitemap

If you have no need of a sitemap index file, i.e. you're never going to have more than 50k URLs, then something like this should suffice:

use Netglue\Sitemap\Sitemap;

$sitemap = new Sitemap('some-file.xml', 'http://base-host-and-scheme.com');
$sitemap->addUri('/somewhere');

$xml = (string) $sitemap; // or $sitemap->toXmlString()

// Now do whatever with your xml…

The signature for Sitemap::addUri() is:

Sitemap::addUri(
    \Laminas\Uri\UriInterface|string $uri,
    ?\DateTimeInterface $lastMod = null,
    ?string $changeFreq = null,
    ?float $priority = null
) : void;

Multiple sitemaps with an index

Adding urls to an index will automatically generate new sitemaps when the max location count is reached for each sitemap. Each sitemap will be named sitemap-{index}.xml where {index} starts at zero

use Netglue\Sitemap\SitemapIndex;
use Netglue\Sitemap\Sitemap;

$index = new SitemapIndex('http://baseurl.host');
// Optionally limit sitemap size (Default is 50k)
$index->setMaxEntriesPerSitemap(10);
// Add a shed load of relative, or absolute URIs
$index->addUri('/someplace');
// ... 

// Retrieve the sitemaps and do something with them:
foreach ($index->getSitemaps() as $sitemap) {
    /** @var Sitemap $sitemap */
    $xml = (string) $sitemap;
    $filename = $sitemap->getName(); // i.e 'sitemap-0.xml'
}

// Do somthing with the Index XML
$indexXml = (string) $index;

Writing to Disk

I figured that if anyone uses this lib, there's a good chance that they may wish to write sitemaps to disk, so it also includes a simple writer class

use Netglue\Sitemap\Writer\FileWriter;
use Netglue\Sitemap\SitemapIndex;

$writer = new FileWriter('/path/to/disk/location');
$writer->writeIndex($index);

The above will write a Sitemap Index and all the sitemaps found to the given directory. You can provide a filename too instead of the default sitemap-index.xml. If you are working with a single sitemap, then this will do the job:

use Netglue\Sitemap\Writer\FileWriter;
use Netglue\Sitemap\Sitemap;

$writer = new FileWriter('/path/to/disk/location');
$writer->writeSitemap($sitemap, 'my-sitemap.xml');

The filename is optional and defaults to $sitemap->getName()

Exceptions

Consistent Exceptions are thrown that all implement Netglue\Sitemap\Exception\ExceptionInterface. For example, changefreq, when provided must be valid according to the schema. Priority must be a float between 0 and 1 etc.

License

This lib is MIT Licensed. Do what you like with it, but don't blame anyone if there's a problem

Feedback and Contributions…

… are welcomed. Please add tests for any fixes or feature pull requests.

About

Netglue is a web design firm based in Devon, UK.

We hope this is useful to you and we’d appreciate feedback either way :)


All versions of sitemap-builder with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
ext-xmlwriter Version *
laminas/laminas-uri Version ^2.7
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package netglue/sitemap-builder contains the following files

Loading the files please wait ....