-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNavigationServiceFactory.php
More file actions
58 lines (48 loc) · 1.97 KB
/
NavigationServiceFactory.php
File metadata and controls
58 lines (48 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
namespace Dot\Navigation\Factory;
use Dot\Authorization\AuthorizationInterface;
use Dot\Helpers\Route\RouteHelper;
use Dot\Navigation\Options\NavigationOptions;
use Dot\Navigation\Provider\Factory;
use Dot\Navigation\Provider\ProviderPluginManager;
use Dot\Navigation\Service\Navigation;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
class NavigationServiceFactory
{
public const MESSAGE_MISSING_PLUGIN_MANAGER = 'Unable to find ProviderPluginManager in the container';
public const MESSAGE_MISSING_ROUTE_HELPER = 'Unable to find RouteHelper in the container';
public const MESSAGE_MISSING_NAVIGATION_OPTIONS = 'Unable to find NavigationOptions in the container';
/**
* @throws NotFoundExceptionInterface
* @throws ContainerExceptionInterface
* @throws Exception
*/
public function __invoke(ContainerInterface $container): Navigation
{
if (! $container->has(RouteHelper::class)) {
throw new Exception(self::MESSAGE_MISSING_ROUTE_HELPER);
}
if (! $container->has(ProviderPluginManager::class)) {
throw new Exception(self::MESSAGE_MISSING_PLUGIN_MANAGER);
}
if (! $container->has(NavigationOptions::class)) {
throw new Exception(self::MESSAGE_MISSING_NAVIGATION_OPTIONS);
}
/** @var NavigationOptions $options */
$options = $container->get(NavigationOptions::class);
$service = new Navigation(
new Factory($container, $container->get(ProviderPluginManager::class)),
$container->get(RouteHelper::class),
$options,
$container->has(AuthorizationInterface::class)
? $container->get(AuthorizationInterface::class)
: null
);
$service->setIsActiveRecursion($options->getActiveRecursion());
return $service;
}
}