Skip to content

Commit

Permalink
submenuIfCan refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiandedeyne committed Aug 1, 2016
1 parent ab4adf1 commit b84850e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"illuminate/auth": "~5.1.14|~5.2.0|~5.3.0",
"illuminate/contracts": "~5.1.14|~5.2.0|~5.3.0",
"illuminate/support": "~5.1.14|~5.2.0|~5.3.0",
"spatie/menu": "^1.1.0"
"spatie/menu": "^1.2.1"
},
"require-dev": {
"orchestra/testbench": "^3.1",
Expand Down
21 changes: 5 additions & 16 deletions src/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,28 +204,17 @@ public function routeIfCan($authorization, string $name, string $text, array $pa
*/
public function submenuIfCan($authorization, $header, $menu = null)
{
list($authorization, $header, $menu) = $this->parseSubmenuIfCanArgs(func_get_args());
list($authorization, $header, $menu) = $this->parseSubmenuIfCanArgs(...func_get_args());

if (is_callable($menu)) {
$transformer = $menu;
$menu = $this->blueprint();
$transformer($menu);
}

if ($header instanceof Item) {
$header = $header->render();
}
$menu = $this->createSubmenuMenu($menu);
$header = $this->createSubmenuHeader($header);

return $this->addIfCan($authorization, $menu->prependIf($header, $header));
}

protected function parseSubmenuIfCanArgs($args): array
protected function parseSubmenuIfCanArgs($authorization, ...$args): array
{
if (count($args) === 2) {
return [$args[0], '', $args[1]];
}

return [$args[0], $args[1], $args[2]];
return array_merge([$authorization], $this->parseSubmenuArgs($args));
}

/**
Expand Down

0 comments on commit b84850e

Please sign in to comment.