vendor/ezsystems/ezplatform-admin-ui/src/bundle/Templating/Twig/UiConfigExtension.php line 46

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. declare(strict_types=1);
  7. namespace EzSystems\EzPlatformAdminUiBundle\Templating\Twig;
  8. use EzSystems\EzPlatformAdminUi\UI\Config\Aggregator;
  9. use ProxyManager\Factory\LazyLoadingValueHolderFactory;
  10. use ProxyManager\Proxy\LazyLoadingInterface;
  11. use Twig\Environment;
  12. use Twig_Extension;
  13. use Twig_Extension_GlobalsInterface;
  14. use EzSystems\EzPlatformAdminUi\UI\Config\ConfigWrapper;
  15. /**
  16.  * Exports `admin_ui_config` providing UI Config as a global Twig variable.
  17.  */
  18. class UiConfigExtension extends Twig_Extension implements Twig_Extension_GlobalsInterface
  19. {
  20.     /** @var \Twig\Environment */
  21.     protected $twig;
  22.     /** @var \EzSystems\EzPlatformAdminUi\UI\Config\Aggregator */
  23.     protected $aggregator;
  24.     /**
  25.      * @param \Twig\Environment $twig
  26.      * @param \EzSystems\EzPlatformAdminUi\UI\Config\Aggregator $aggregator
  27.      */
  28.     public function __construct(Environment $twigAggregator $aggregator)
  29.     {
  30.         $this->twig $twig;
  31.         $this->aggregator $aggregator;
  32.     }
  33.     /**
  34.      * @return array
  35.      */
  36.     public function getGlobals(): array
  37.     {
  38.         return [
  39.             'admin_ui_config' => $this->createConfigWrapper(),
  40.         ];
  41.     }
  42.     /**
  43.      * Create lazy loaded configuration.
  44.      *
  45.      * @return \EzSystems\EzPlatformAdminUi\UI\Config\ConfigWrapper
  46.      */
  47.     private function createConfigWrapper(): ConfigWrapper
  48.     {
  49.         $factory = new LazyLoadingValueHolderFactory();
  50.         $initializer = function (&$wrappedObjectLazyLoadingInterface $proxy$method, array $parameters, &$initializer) {
  51.             $initializer null;
  52.             $wrappedObject = new ConfigWrapper($this->aggregator->getConfig());
  53.             return true;
  54.         };
  55.         return $factory->createProxy(ConfigWrapper::class, $initializer);
  56.     }
  57. }