File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Novactive \EzMenuManager \Exception ;
6+
7+ use Exception ;
8+ use Throwable ;
9+
10+ class MenuNotFoundException extends Exception
11+ {
12+ public function __construct ($ identifier , Throwable $ previous = null )
13+ {
14+ $ message = sprintf ("Could not find menu with identifier '%s' " , $ identifier );
15+ parent ::__construct ($ message , 404 , $ previous );
16+ }
17+ }
Original file line number Diff line number Diff line change 1717use Doctrine \ORM \EntityManagerInterface ;
1818use Ibexa \Contracts \Core \Repository \LocationService ;
1919use Ibexa \Contracts \Core \Repository \Values \Content \Location ;
20+ use Novactive \EzMenuManager \Exception \MenuNotFoundException ;
2021use Novactive \EzMenuManager \MenuItem \MenuItemTypeRegistry ;
2122use Novactive \EzMenuManagerBundle \Entity \Menu ;
2223use Novactive \EzMenuManagerBundle \Entity \MenuItem ;
@@ -80,18 +81,32 @@ public function getLocationMenuItemsInMenu(Location $location, Menu $menu)
8081 /**
8182 * @param $menuId
8283 *
84+ * @throws \Novactive\EzMenuManager\Exception\MenuNotFoundException
85+ *
8386 * @return Menu|object|null
8487 */
8588 public function loadMenu ($ menuId )
8689 {
87- return $ this ->em ->getRepository (Menu::class)->find ($ menuId );
90+ $ menu = $ this ->em ->getRepository (Menu::class)->find ($ menuId );
91+ if (!$ menu ) {
92+ throw new MenuNotFoundException ($ menuId );
93+ }
94+
95+ return $ menu ;
8896 }
8997
9098 /**
99+ * @throws \Novactive\EzMenuManager\Exception\MenuNotFoundException
100+ *
91101 * @return Menu|object|null
92102 */
93103 public function loadMenuByRemoteId (string $ remoteId )
94104 {
95- return $ this ->em ->getRepository (Menu::class)->findOneBy (['remoteId ' => $ remoteId ]);
105+ $ menu = $ this ->em ->getRepository (Menu::class)->findOneBy (['remoteId ' => $ remoteId ]);
106+ if (!$ menu ) {
107+ throw new MenuNotFoundException ($ remoteId );
108+ }
109+
110+ return $ menu ;
96111 }
97112}
You can’t perform that action at this time.
0 commit comments