Skip to content

Commit

Permalink
Added iterator capabilities to the menu class (#73)
Browse files Browse the repository at this point in the history
* Added iterator capabilities to the menu class

* Replaced @return doc block with an actual return type

* Minor code style fix
  • Loading branch information
axlon authored and sebastiandedeyne committed Oct 23, 2018
1 parent 08f74e5 commit f465443
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

namespace Spatie\Menu;

use ArrayIterator;
use Countable;
use IteratorAggregate;
use Spatie\Menu\Html\Tag;
use Spatie\Menu\Html\Attributes;
use Spatie\Menu\Helpers\Reflection;
use Spatie\Menu\Traits\Conditions as ConditionsTrait;
use Spatie\Menu\Traits\HasTextAttributes as HasAttributesTrait;
use Spatie\Menu\Traits\HasHtmlAttributes as HasHtmlAttributesTrait;
use Spatie\Menu\Traits\HasParentAttributes as HasParentAttributesTrait;
use Traversable;

class Menu implements Item, Countable, HasHtmlAttributes, HasParentAttributes
class Menu implements Item, Countable, HasHtmlAttributes, HasParentAttributes, IteratorAggregate
{
use HasHtmlAttributesTrait, HasParentAttributesTrait, ConditionsTrait, HasAttributesTrait;

Expand Down Expand Up @@ -721,4 +724,9 @@ public function __toString(): string
{
return $this->render();
}

public function getIterator(): Traversable
{
return new ArrayIterator($this->items);
}
}

0 comments on commit f465443

Please sign in to comment.