From 3154f1e5b703af72f893d6726bcb6b5df6ff7c17 Mon Sep 17 00:00:00 2001 From: Barry Brands Date: Wed, 7 Feb 2024 21:40:53 +0100 Subject: [PATCH 1/2] Twig getObject extension --- api/src/Twig/MappingExtension.php | 1 + api/src/Twig/MappingRuntime.php | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/api/src/Twig/MappingExtension.php b/api/src/Twig/MappingExtension.php index 6308c6c99..6145279a4 100644 --- a/api/src/Twig/MappingExtension.php +++ b/api/src/Twig/MappingExtension.php @@ -13,6 +13,7 @@ public function getFunctions() new TwigFunction('map', [MappingRuntime::class, 'map']), new TwigFunction('dotToObject', [MappingRuntime::class, 'dotToArray']), new TwigFunction('arrayValues', [MappingRuntime::class, 'arrayValues']), + new TwigFunction('getObject', [MappingRuntime::class, 'getObject']), ]; } } diff --git a/api/src/Twig/MappingRuntime.php b/api/src/Twig/MappingRuntime.php index 87b385b24..95700abeb 100644 --- a/api/src/Twig/MappingRuntime.php +++ b/api/src/Twig/MappingRuntime.php @@ -4,6 +4,7 @@ use Adbar\Dot; use CommonGateway\CoreBundle\Service\MappingService; +use CommonGateway\CoreBundle\Service\CacheService; use Doctrine\ORM\EntityManagerInterface; use Twig\Extension\RuntimeExtensionInterface; @@ -11,11 +12,13 @@ class MappingRuntime implements RuntimeExtensionInterface { private MappingService $mappingService; private EntityManagerInterface $entityManager; + private CacheService $cacheService; - public function __construct(MappingService $mappingService, EntityManagerInterface $entityManager) + public function __construct(MappingService $mappingService, EntityManagerInterface $entityManager, CacheService $cacheService) { $this->entityManager = $entityManager; $this->mappingService = $mappingService; + $this->cacheService = $cacheService; } /** @@ -66,4 +69,16 @@ public function arrayValues(array $array): array { return array_values($array); } + + /** + * Makes it possible to get a object with the cacheService in twig. + * + * @param string $id The id of the object to fetch. + * + * @return array The fetched object. + */ + public function getObject(string $id): array + { + return $this->cacheService->getObject($id); + } } From 970e2f342fe8826726e4270391d63dd87a980fa6 Mon Sep 17 00:00:00 2001 From: Barry Brands Date: Wed, 7 Feb 2024 21:41:04 +0100 Subject: [PATCH 2/2] typo fix initialize --- api/src/Command/InitializationCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/Command/InitializationCommand.php b/api/src/Command/InitializationCommand.php index f3245572c..71707915a 100644 --- a/api/src/Command/InitializationCommand.php +++ b/api/src/Command/InitializationCommand.php @@ -91,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $config['unsafe'] = $input->getOption('unsafe'); // Throw the event - $io->info('Trowing commongateway.pre.initialization event'); + $io->info('Throwing commongateway.pre.initialization event'); $event = new ActionEvent('commongateway.pre.initialization', []); $this->eventDispatcher->dispatch($event, 'commongateway.pre.initialization'); @@ -293,7 +293,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io->success('Successfully finished setting basic configuration'); // todo: actualy throw it - $io->info('Trowing commongateway.post.initialization event'); + $io->info('Throwing commongateway.post.initialization event'); // Throw the event $event = new ActionEvent('commongateway.post.initialization', []);