Skip to content

Commit

Permalink
Merge 28b039d into 184cf7e
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Jul 14, 2017
2 parents 184cf7e + 28b039d commit 6e6517a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/SitemapManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
use Arcanedev\LaravelSitemap\Contracts\Entities\Sitemap as SitemapContract;
use Arcanedev\LaravelSitemap\Contracts\SitemapManager as SitemapManagerContract;
use Arcanedev\LaravelSitemap\Entities\Sitemap;
use Arcanedev\LaravelSitemap\Exceptions\SitemapException;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

/**
* Class SitemapManager
Expand Down Expand Up @@ -121,7 +123,18 @@ public function get($name, $default = null)
*/
public function has($name)
{
return $this->sitemaps->has($name);
if ( ! Str::contains($name, '.')) {
return $this->sitemaps->has($name);
}

list($name, $key) = explode('.', $name, 2);

/** @var \Arcanedev\LaravelSitemap\Contracts\Entities\Sitemap|null $map */
$map = $this->sitemaps->filter(function (Sitemap $map) use ($name) {
return $map->isExceeded();
})->get($name);

return is_null($map) ? false : $map->chunk()->has(intval($key));
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/SitemapManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,11 @@ public function it_can_chunk_a_huge_sitemap_on_render()
$this->assertMatchesSnapshot($this->manager->render('blog'));

foreach (range(1, 5) as $index) {
$this->assertTrue($this->manager->has("blog.$index"), "Issue with the index: $index");
$this->assertMatchesSnapshot($this->manager->render("blog.$index"));
}

$this->assertFalse($this->manager->has('blog.6'));
$this->assertNull($this->manager->render('blog.6'));
}

Expand Down

0 comments on commit 6e6517a

Please sign in to comment.