Skip to content
Permalink
Browse files

Think of a better name for the splitting classes.

  • Loading branch information...
Mathew Davies
Mathew Davies committed Oct 15, 2017
1 parent a49f394 commit 3e1034a5052d5ff92a9b04709643be8e8c722b85
@@ -1,12 +1,12 @@
<?php
namespace spec\Thepixeldeveloper\Sitemap\Splitter;
namespace spec\Thepixeldeveloper\Sitemap;
use PhpSpec\ObjectBehavior;
use Thepixeldeveloper\Sitemap\Url;
use Thepixeldeveloper\Sitemap\Urlset;
class CollectionSplitterSpec extends ObjectBehavior
class ChunkedUrlsetSpec extends ObjectBehavior
{
function let(Urlset $urlset)
{
@@ -1,12 +1,10 @@
<?php declare(strict_types=1);
namespace Thepixeldeveloper\Sitemap\Splitter;
namespace Thepixeldeveloper\Sitemap;
use Thepixeldeveloper\Sitemap\Collection;
use Thepixeldeveloper\Sitemap\Interfaces\CollectionSplitterInterface;
use Thepixeldeveloper\Sitemap\Interfaces\VisitorInterface;
class CollectionSplitter implements CollectionSplitterInterface
abstract class ChunkedCollection
{
const LIMIT = 50000;
@@ -15,32 +13,24 @@ class CollectionSplitter implements CollectionSplitterInterface
*/
private $collections;
/**
* @var Collection
*/
private $collection;
/**
* @var int
*/
private $count;
/**
* SitemapSplitter constructor.
*
* @param Collection $collection
*/
public function __construct(Collection $collection)
public function __construct()
{
$this->collections = [];
$this->collection = $collection;
$this->count = 0;
}
public function add(VisitorInterface $visitor)
{
if ($this->count === 0 || $this->count === self::LIMIT) {
$this->count = 0; $this->collections[] = clone $this->collection;
$this->count = 0; $this->collections[] = $this->getCollectionClass();
}
$this->collections[count($this->collections) - 1]->add($visitor);
@@ -54,4 +44,6 @@ public function getCollections(): array
{
return $this->collections;
}
abstract protected function getCollectionClass(): Collection;
}
@@ -0,0 +1,11 @@
<?php declare(strict_types=1);
namespace Thepixeldeveloper\Sitemap;
class ChunkedSitemapIndex extends ChunkedCollection
{
protected function getCollectionClass(): Collection
{
return new SitemapIndex();
}
}
@@ -0,0 +1,11 @@
<?php declare(strict_types=1);
namespace Thepixeldeveloper\Sitemap;
class ChunkedUrlset extends ChunkedCollection
{
protected function getCollectionClass(): Collection
{
return new Urlset();
}
}

This file was deleted.

0 comments on commit 3e1034a

Please sign in to comment.
You can’t perform that action at this time.