Skip to content
Permalink
Browse files

Allow mixing of strings and arrays/collections in link list

  • Loading branch information...
tbuteler committed Mar 7, 2016
1 parent 187809e commit d0576db8bd16510c3637652a5a4d393d0a569094
Showing with 18 additions and 3 deletions.
  1. +18 −3 src/Controller.php
@@ -2,6 +2,7 @@
namespace Clumsy\Sitemap;
use ArrayAccess;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
@@ -20,9 +21,23 @@ protected function missing()
return abort(404);
}
protected function isGroup($var)
{
return is_array($var) || $var instanceof ArrayAccess;
}
protected function addLink($link, $lastmod = null, $priority = null, $changefreq = null)
{
$this->sitemap->addLink($link, $lastmod, $priority, $changefreq);
if ($this->isGroup($link)) {
foreach ($link as $l) {
$this->addLink($l, $lastmod, $priority, $changefreq);
}
} else {
$this->sitemap->addLink($link, $lastmod, $priority, $changefreq);
}
}
protected function addGroup(array $group)
@@ -47,7 +62,7 @@ protected function parseGroups()
foreach ($this->groups as $group) {
if (is_array($group)) {
if ($this->isGroup($group)) {
$this->addGroup($group);
continue;
}
@@ -69,7 +84,7 @@ public function render()
return $this->missing();
}
if (!is_array($this->groups) || !count($this->groups)) {
if (!$this->isGroup($this->groups) || !count($this->groups)) {
return $this->missing();
}

0 comments on commit d0576db

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