Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give the ability to set groupName on Sitemap Factory #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"require": {
"php": ">=5.4",
"league/flysystem": "1.0.*"
"league/flysystem": "^1.1 || ^3"
},
"autoload": {
"files": [
Expand Down
42 changes: 35 additions & 7 deletions src/SitemapFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
use ArrayObject;
use DateTime;
use Iterator;
use League\Flysystem\FilesystemInterface;
use League\Flysystem\FilesystemOperator;
use RuntimeException;

class SitemapFactory
{
/**
* @var FilesystemInterface
* @var FilesystemOperator
*/
protected $filesystem = null;

Expand All @@ -20,22 +20,28 @@ class SitemapFactory
*/
protected $baseUrl = '';

/**
* @var string
*/
protected $groupName = '';

/**
* @var array
*/
protected $filesCreated = [];

/**
* @param FilesystemInterface $filesystem
* @param FilesystemOperator $filesystem
*/
public function __construct(FilesystemInterface $filesystem)
public function __construct(FilesystemOperator $filesystem)
{
$this->filesystem = $filesystem;
$this->groupName = $this->randomHash();
}

/**
* Gets the Filesystem.
* @return FilesystemInterface
* @return FilesystemOperator
*/
public function getFilesystem()
{
Expand Down Expand Up @@ -64,6 +70,28 @@ public function getBaseUrl()
return $this->baseUrl;
}

/**
* Sets the Group Name for sitemap file names.
*
* @param string $groupName
* @return $this
*/
public function setGroupName($groupName)
{
$this->groupName = $groupName;

return $this;
}

/**
* Gets the Group Name for sitemap file names.
* @return string
*/
public function getGroupName()
{
return $this->groupName;
}

/**
* Gets the array of files created.
* @return array
Expand All @@ -81,7 +109,7 @@ public function getFilesCreated()
*/
public function createSitemap(Iterator $iterator)
{
$groupName = $this->randomHash();
$groupName = $this->groupName;
$paths = new ArrayObject();
$sitemap = new Sitemap();
foreach ($iterator as $entry) {
Expand Down Expand Up @@ -109,7 +137,7 @@ public function createSitemap(Iterator $iterator)
*/
public function createSitemapIndex(Iterator $sitemaps)
{
$groupName = $this->randomHash();
$groupName = $this->groupName;
$sitemapIndexes = new ArrayObject();
$sitemapIndex = new SitemapIndex();
$lastmod = date(DateTime::W3C);
Expand Down