diff --git a/src/Service/RestrictIpService.php b/src/Service/RestrictIpService.php index e1d885cc5d7fa413c7c48b04278cae81d614e82e..c9b2066ba1e710b162193bf81686c7ba2bc4d9a1 100644 --- a/src/Service/RestrictIpService.php +++ b/src/Service/RestrictIpService.php @@ -71,20 +71,20 @@ class RestrictIpService implements RestrictIpServiceInterface, ContainerInjectio * The Path Matcher service. * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler * The Module Handler service. - * @param \Drupal\user\UserDataInterface $userData + * @param \Drupal\user\UserDataInterface|null $userData * The User Data service. * @param \Drupal\ip2country\Ip2CountryLookup|null $ip2CountryLookupService * An ip2CountryLookupService object. */ public function __construct( protected AccountProxyInterface $currentUser, - CurrentPathStack $currentPathStack, + protected CurrentPathStack $currentPathStack, protected ConfigFactoryInterface $configFactory, protected RequestStack $requestStack, protected RestrictIpMapperInterface $mapper, protected PathMatcherInterface $pathMatcher, protected ModuleHandlerInterface $moduleHandler, - protected UserDataInterface $userData, + protected ?UserDataInterface $userData = NULL, ?Ip2CountryLookup $ip2CountryLookupService = NULL, ) { $this->currentPath = strtolower($currentPathStack->getPath()); @@ -97,16 +97,21 @@ class RestrictIpService implements RestrictIpServiceInterface, ContainerInjectio * {@inheritDoc} */ public static function create(ContainerInterface $container): static { + $ip2CountryLookupService = NULL; + if ($container->has('ip2country.lookup')) { + $ip2CountryLookupService = $container->get('ip2country.lookup'); + } + return new static( $container->get('current_user'), + $container->get('path.current'), + $container->get('config.factory'), + $container->get('request_stack'), $container->get('restrict_ip.mapper'), $container->get('path.matcher'), $container->get('module_handler'), $container->get('user.data'), - $container->get('path.current'), - $container->get('config.factory'), - $container->get('request_stack'), - $container->get('ip2country.lookup'), + $ip2CountryLookupService ); }