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

Commit 4d0ccdc

Browse files
committed
Allow knp-menu 3.x
1 parent 7508e13 commit 4d0ccdc

File tree

8 files changed

+23
-27
lines changed

8 files changed

+23
-27
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"php": "^7.1",
1919
"symfony/framework-bundle": "^2.8 || ^3.3 || ^4.0",
2020
"symfony/validator": "^2.8 || ^3.3 || ^4.0",
21-
"knplabs/knp-menu-bundle": "^2.2.0",
22-
"knplabs/knp-menu": "^2.0.0"
21+
"knplabs/knp-menu-bundle": "^2.2 || ^3.0",
22+
"knplabs/knp-menu": "^2.0 || ^3.0"
2323
},
2424
"require-dev": {
2525
"symfony/monolog-bundle": "~3.1",

src/Extension/ContentExtension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(UrlGeneratorInterface $contentRouter)
4545
*
4646
* @return array
4747
*/
48-
public function buildOptions(array $options)
48+
public function buildOptions(array $options): array
4949
{
5050
$options = array_merge([
5151
'content' => null,
@@ -86,7 +86,7 @@ public function buildOptions(array $options)
8686
* @param ItemInterface $item
8787
* @param array $options
8888
*/
89-
public function buildItem(ItemInterface $item, array $options)
89+
public function buildItem(ItemInterface $item, array $options): void
9090
{
9191
}
9292

src/Loader/VotingNodeLoader.php

+5-12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Cmf\Bundle\MenuBundle\Loader;
1313

1414
use Knp\Menu\FactoryInterface;
15+
use Knp\Menu\ItemInterface;
1516
use Knp\Menu\Loader\NodeLoader;
1617
use Knp\Menu\NodeInterface;
1718
use Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr\Menu;
@@ -40,7 +41,7 @@ public function __construct(FactoryInterface $factory, EventDispatcherInterface
4041
$this->dispatcher = $dispatcher;
4142
}
4243

43-
public function load($data)
44+
public function load($data): ItemInterface
4445
{
4546
if (!$this->supports($data)) {
4647
throw new \InvalidArgumentException(sprintf(
@@ -52,21 +53,13 @@ public function load($data)
5253
$this->dispatcher->dispatch(Events::CREATE_ITEM_FROM_NODE, $event);
5354

5455
if ($event->isSkipNode()) {
55-
if ($data instanceof Menu) {
56-
// create an empty menu root to avoid the knp menu from failing.
57-
return $this->menuFactory->createItem('');
58-
}
59-
60-
return;
56+
// create an empty menu root to avoid the knp menu from failing.
57+
return $this->menuFactory->createItem('');
6158
}
6259

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

65-
if (empty($item)) {
66-
return;
67-
}
68-
69-
if ($event->isSkipChildren()) {
62+
if (empty($item) || $event->isSkipChildren()) {
7063
return $item;
7164
}
7265

src/Model/MenuNode.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function setContent($content)
145145
/**
146146
* {@inheritdoc}
147147
*/
148-
public function getOptions()
148+
public function getOptions(): array
149149
{
150150
$options = parent::getOptions();
151151

src/Model/MenuNodeBase.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function setId($id)
172172
/**
173173
* {@inheritdoc}
174174
*/
175-
public function getName()
175+
public function getName(): string
176176
{
177177
return $this->name;
178178
}
@@ -349,7 +349,7 @@ public function setChildrenAttributes(array $attributes)
349349
*
350350
* @return NodeInterface[]
351351
*/
352-
public function getChildren()
352+
public function getChildren(): \Traversable
353353
{
354354
$children = [];
355355
foreach ($this->children as $child) {
@@ -359,7 +359,7 @@ public function getChildren()
359359
$children[] = $child;
360360
}
361361

362-
return $children;
362+
return new \ArrayIterator($children);
363363
}
364364

365365
/**
@@ -573,7 +573,7 @@ public function isDisplayable()
573573
/**
574574
* {@inheritdoc}
575575
*/
576-
public function getOptions()
576+
public function getOptions(): array
577577
{
578578
return [
579579
'uri' => $this->getUri(),

src/Provider/PhpcrMenuProvider.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function getPrefetch()
140140
*
141141
* @throws \InvalidArgumentException if the menu can not be found
142142
*/
143-
public function get($name, array $options = [])
143+
public function get(string $name, array $options = []): ItemInterface
144144
{
145145
$menu = $this->find($name, true);
146146

@@ -164,7 +164,7 @@ public function get($name, array $options = [])
164164
*
165165
* @return bool Whether a menu with this name can be loaded by this provider
166166
*/
167-
public function has($name, array $options = [])
167+
public function has(string $name, array $options = []): bool
168168
{
169169
return $this->find($name, false) instanceof NodeInterface;
170170
}

src/QuietFactory.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Knp\Menu\Factory\ExtensionInterface;
1515
use Knp\Menu\FactoryInterface;
16+
use Knp\Menu\ItemInterface;
1617
use LogicException;
1718
use Psr\Log\LoggerInterface;
1819
use Symfony\Component\Routing\Exception\RouteNotFoundException;
@@ -54,7 +55,7 @@ public function __construct(FactoryInterface $innerFactory, LoggerInterface $log
5455
/**
5556
* {@inheritdoc}
5657
*/
57-
public function createItem($name, array $options = [])
58+
public function createItem(string $name, array $options = []): ItemInterface
5859
{
5960
try {
6061
return $this->innerFactory->createItem($name, $options);
@@ -67,7 +68,7 @@ public function createItem($name, array $options = [])
6768
}
6869

6970
if (!$this->allowEmptyItems) {
70-
return;
71+
return $this->innerFactory->createItem('');
7172
}
7273

7374
// remove route and content options

src/Voter/UriPrefixVoter.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ public function setRequest(Request $request = null)
6868
/**
6969
* {@inheritdoc}
7070
*/
71-
public function matchItem(ItemInterface $item)
71+
public function matchItem(ItemInterface $item): ?bool
7272
{
7373
$request = $this->getRequest();
7474
if (!$request) {
75-
return;
75+
return false;
7676
}
7777

7878
$content = $item->getExtra('content');
@@ -84,6 +84,8 @@ public function matchItem(ItemInterface $item)
8484
return true;
8585
}
8686
}
87+
88+
return false;
8789
}
8890

8991
private function getRequest()

0 commit comments

Comments
 (0)