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

Commit bd78524

Browse files
authored
Merge pull request #282 from symfony-cmf/fix-menu-not-found-exception
report correct problem when menu not found
2 parents 587efb3 + e3ba1be commit bd78524

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/Provider/PhpcrMenuProvider.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -232,24 +232,32 @@ protected function find($name, array $options, $throw)
232232
}
233233

234234
if ($this->getPrefetch() > 0) {
235-
try {
236-
if (
235+
if (
237236
$session instanceof Session
238237
&& 0 < $session->getSessionOption(Session::OPTION_FETCH_DEPTH)
239238
&& 0 === strncmp($path, $this->getMenuRoot(), strlen($this->getMenuRoot()))
240239
) {
241-
// we have jackalope with a fetch depth. prefetch all menu
240+
// we have jackalope with a fetch depth. prefetch all menu
242241
// nodes of all menues.
243-
$session->getNode($this->getMenuRoot(), $this->getPrefetch() + 1);
244-
} else {
242+
try {
243+
$session->getNode($this->getMenuRoot(), $this->getPrefetch() + 1);
244+
} catch (PathNotFoundException $e) {
245+
if ($throw) {
246+
throw new \InvalidArgumentException(sprintf('The menu root "%s" does not exist.', $this->getMenuRoot()));
247+
}
248+
249+
return false;
250+
}
251+
} else {
252+
try {
245253
$session->getNode($path, $this->getPrefetch());
246-
}
247-
} catch (PathNotFoundException $e) {
248-
if ($throw) {
249-
throw new \InvalidArgumentException(sprintf('The menu root "%s" does not exist.', $this->getMenuRoot()));
250-
}
254+
} catch (PathNotFoundException $e) {
255+
if ($throw) {
256+
throw new \InvalidArgumentException(sprintf('No menu found at "%s".', $path));
257+
}
251258

252-
return false;
259+
return false;
260+
}
253261
}
254262
}
255263

0 commit comments

Comments
 (0)