vendor/se7enxweb/legacy-bridge/bundle/LegacyMapper/LegacyBundles.php line 68

Open in your IDE?
  1. <?php
  2. /**
  3. * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  4. * @license For full copyright and license information view LICENSE file distributed with this source code.
  5. */
  6. namespace eZ\Bundle\EzPublishLegacyBundle\LegacyMapper;
  7. use eZ\Publish\Core\MVC\Legacy\LegacyEvents;
  8. use eZ\Publish\Core\MVC\Legacy\Event\PreBuildKernelEvent;
  9. use eZ\Publish\Core\MVC\ConfigResolverInterface;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. /**
  12. * Enables extensions from LegacyBundle in the Legacy Kernel.
  13. */
  14. class LegacyBundles implements EventSubscriberInterface
  15. {
  16. /**
  17. * @var \eZ\Publish\Core\MVC\ConfigResolverInterface
  18. */
  19. private $configResolver;
  20. /**
  21. * @var array
  22. */
  23. private $options;
  24. /**
  25. * Disables the feature when set using setEnabled().
  26. *
  27. * @var bool
  28. */
  29. private $enabled = true;
  30. public function __construct(
  31. ConfigResolverInterface $configResolver,
  32. array $options = []
  33. ) {
  34. $this->configResolver = $configResolver;
  35. $this->options = $options;
  36. }
  37. /**
  38. * Toggles the feature.
  39. *
  40. * @param bool $isEnabled
  41. */
  42. public function setEnabled($isEnabled)
  43. {
  44. $this->enabled = (bool)$isEnabled;
  45. }
  46. public static function getSubscribedEvents()
  47. {
  48. return [
  49. LegacyEvents::PRE_BUILD_LEGACY_KERNEL => ['onBuildKernel', 128],
  50. ];
  51. }
  52. /**
  53. * Adds settings to the parameters that will be injected into the legacy kernel.
  54. *
  55. * @param \eZ\Publish\Core\MVC\Legacy\Event\PreBuildKernelEvent $event
  56. *
  57. * @todo Cache computed settings somehow
  58. */
  59. public function onBuildKernel(PreBuildKernelEvent $event)
  60. {
  61. if (!$this->enabled) {
  62. return;
  63. }
  64. if (!isset($this->options['extensions'])) {
  65. return;
  66. }
  67. $settings = ['site.ini/ExtensionSettings/ActiveExtensions' => $this->options['extensions']];
  68. $event->getParameters()->set(
  69. 'injected-merge-settings',
  70. $settings + (array)$event->getParameters()->get('injected-merge-settings')
  71. );
  72. }
  73. }