vendor/netgen/layouts-ibexa/bundle/Configuration/ConfigResolverConfiguration.php line 43

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Netgen\Bundle\LayoutsIbexaBundle\Configuration;
  4. use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
  5. use Netgen\Bundle\LayoutsBundle\Configuration\ConfigurationInterface;
  6. use Netgen\Bundle\LayoutsBundle\Exception\ConfigurationException;
  7. /**
  8. * Implementation of ConfigurationInterface that uses Ibexa CMS
  9. * config resolver to retrieve parameters from the container.
  10. *
  11. * This means that the returned values will be the ones defined
  12. * in the current Ibexa CMS scope of the request.
  13. *
  14. * @final
  15. */
  16. class ConfigResolverConfiguration implements ConfigurationInterface
  17. {
  18. public function __construct(
  19. private ConfigResolverInterface $configResolver,
  20. private ConfigurationInterface $fallbackConfiguration,
  21. ) {}
  22. public function hasParameter(string $parameterName): bool
  23. {
  24. $hasParam = $this->configResolver->hasParameter(
  25. $parameterName,
  26. ConfigurationInterface::PARAMETER_NAMESPACE,
  27. );
  28. if (!$hasParam) {
  29. $hasParam = $this->fallbackConfiguration->hasParameter($parameterName);
  30. }
  31. return $hasParam;
  32. }
  33. public function getParameter(string $parameterName)
  34. {
  35. if (!$this->hasParameter($parameterName)) {
  36. throw ConfigurationException::noParameter($parameterName);
  37. }
  38. if (
  39. $this->configResolver->hasParameter(
  40. $parameterName,
  41. ConfigurationInterface::PARAMETER_NAMESPACE,
  42. )
  43. ) {
  44. return $this->configResolver->getParameter(
  45. $parameterName,
  46. ConfigurationInterface::PARAMETER_NAMESPACE,
  47. );
  48. }
  49. return $this->fallbackConfiguration->getParameter($parameterName);
  50. }
  51. }