Skip to content
This repository was archived by the owner on Dec 20, 2025. It is now read-only.
This repository was archived by the owner on Dec 20, 2025. It is now read-only.

Suggestion: factory methods or classes to avoid "boilerplate" code #62

@holtkamp

Description

@holtkamp

Is your feature request related to a problem? Please describe.
reduce need for "boilerplate" functions

Describe the solution you'd like
I found myself implementing static factory functions to easily assemble a SitemapIndex or UrlSet:

SitemapIndex::getInstanceForSitemaps($sitemaps): static
UrlSet::getInstanceForUrls($urls): static

Describe alternatives you've considered
Instead of using static factory functions, we might use dedicated factory classes:

SitemapIndexFactory::getInstance($sitemaps = null): Sitemap
UrlSetFactory::getInstance($urls = null): UrlSet

Additional context
Implementation is quite trivial, I currently have:

class SitemapIndex extends \Thepixeldeveloper\Sitemap\SitemapIndex
{
    public static function getInstanceForSitemaps($sitemaps) : self
    {
        $sitemapIndex = new static();
        foreach ($sitemaps as $sitemap) {
            $sitemapIndex->addSitemap($sitemap);
        }

        return $sitemapIndex;
    }
}
class UrlSet extends \Thepixeldeveloper\Sitemap\UrlSet
{
    /**
     * @param OutputInterface[] $urls
     *
     * @return static
     */
    public static function getInstanceForUrls($urls) : self
    {
        $urlSet = new static();
        foreach ($urls as $url) {
            $urlSet->addUrl($url);
        }

        return $urlSet;
    }
}

I can provide a PR, would it be considered? Any suggestions / preference?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions