Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Allow knp-menu 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelVella committed Mar 25, 2021
1 parent 7508e13 commit 4d0ccdc
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 27 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"php": "^7.1",
"symfony/framework-bundle": "^2.8 || ^3.3 || ^4.0",
"symfony/validator": "^2.8 || ^3.3 || ^4.0",
"knplabs/knp-menu-bundle": "^2.2.0",
"knplabs/knp-menu": "^2.0.0"
"knplabs/knp-menu-bundle": "^2.2 || ^3.0",
"knplabs/knp-menu": "^2.0 || ^3.0"
},
"require-dev": {
"symfony/monolog-bundle": "~3.1",
Expand Down
4 changes: 2 additions & 2 deletions src/Extension/ContentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(UrlGeneratorInterface $contentRouter)
*
* @return array
*/
public function buildOptions(array $options)
public function buildOptions(array $options): array
{
$options = array_merge([
'content' => null,
Expand Down Expand Up @@ -86,7 +86,7 @@ public function buildOptions(array $options)
* @param ItemInterface $item
* @param array $options
*/
public function buildItem(ItemInterface $item, array $options)
public function buildItem(ItemInterface $item, array $options): void
{
}

Expand Down
17 changes: 5 additions & 12 deletions src/Loader/VotingNodeLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Cmf\Bundle\MenuBundle\Loader;

use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Knp\Menu\Loader\NodeLoader;
use Knp\Menu\NodeInterface;
use Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr\Menu;
Expand Down Expand Up @@ -40,7 +41,7 @@ public function __construct(FactoryInterface $factory, EventDispatcherInterface
$this->dispatcher = $dispatcher;
}

public function load($data)
public function load($data): ItemInterface
{
if (!$this->supports($data)) {
throw new \InvalidArgumentException(sprintf(
Expand All @@ -52,21 +53,13 @@ public function load($data)
$this->dispatcher->dispatch(Events::CREATE_ITEM_FROM_NODE, $event);

if ($event->isSkipNode()) {
if ($data instanceof Menu) {
// create an empty menu root to avoid the knp menu from failing.
return $this->menuFactory->createItem('');
}

return;
// create an empty menu root to avoid the knp menu from failing.
return $this->menuFactory->createItem('');
}

$item = $event->getItem() ?: $this->menuFactory->createItem($data->getName(), $data->getOptions());

if (empty($item)) {
return;
}

if ($event->isSkipChildren()) {
if (empty($item) || $event->isSkipChildren()) {
return $item;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Model/MenuNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function setContent($content)
/**
* {@inheritdoc}
*/
public function getOptions()
public function getOptions(): array
{
$options = parent::getOptions();

Expand Down
8 changes: 4 additions & 4 deletions src/Model/MenuNodeBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function setId($id)
/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return $this->name;
}
Expand Down Expand Up @@ -349,7 +349,7 @@ public function setChildrenAttributes(array $attributes)
*
* @return NodeInterface[]
*/
public function getChildren()
public function getChildren(): \Traversable
{
$children = [];
foreach ($this->children as $child) {
Expand All @@ -359,7 +359,7 @@ public function getChildren()
$children[] = $child;
}

return $children;
return new \ArrayIterator($children);
}

/**
Expand Down Expand Up @@ -573,7 +573,7 @@ public function isDisplayable()
/**
* {@inheritdoc}
*/
public function getOptions()
public function getOptions(): array
{
return [
'uri' => $this->getUri(),
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/PhpcrMenuProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function getPrefetch()
*
* @throws \InvalidArgumentException if the menu can not be found
*/
public function get($name, array $options = [])
public function get(string $name, array $options = []): ItemInterface
{
$menu = $this->find($name, true);

Expand All @@ -164,7 +164,7 @@ public function get($name, array $options = [])
*
* @return bool Whether a menu with this name can be loaded by this provider
*/
public function has($name, array $options = [])
public function has(string $name, array $options = []): bool
{
return $this->find($name, false) instanceof NodeInterface;
}
Expand Down
5 changes: 3 additions & 2 deletions src/QuietFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Knp\Menu\Factory\ExtensionInterface;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use LogicException;
use Psr\Log\LoggerInterface;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
Expand Down Expand Up @@ -54,7 +55,7 @@ public function __construct(FactoryInterface $innerFactory, LoggerInterface $log
/**
* {@inheritdoc}
*/
public function createItem($name, array $options = [])
public function createItem(string $name, array $options = []): ItemInterface
{
try {
return $this->innerFactory->createItem($name, $options);
Expand All @@ -67,7 +68,7 @@ public function createItem($name, array $options = [])
}

if (!$this->allowEmptyItems) {
return;
return $this->innerFactory->createItem('');
}

// remove route and content options
Expand Down
6 changes: 4 additions & 2 deletions src/Voter/UriPrefixVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public function setRequest(Request $request = null)
/**
* {@inheritdoc}
*/
public function matchItem(ItemInterface $item)
public function matchItem(ItemInterface $item): ?bool
{
$request = $this->getRequest();
if (!$request) {
return;
return false;
}

$content = $item->getExtra('content');
Expand All @@ -84,6 +84,8 @@ public function matchItem(ItemInterface $item)
return true;
}
}

return false;
}

private function getRequest()
Expand Down

0 comments on commit 4d0ccdc

Please sign in to comment.