Skip to content

Commit

Permalink
Merge pull request #1616 from ConductionNL/feature/twig-get-object
Browse files Browse the repository at this point in the history
Useful addition to the twigextension
  • Loading branch information
bbrands02 authored Feb 9, 2024
2 parents 742f728 + 970e2f3 commit 346d2d4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions api/src/Command/InitializationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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', []);
Expand Down
1 change: 1 addition & 0 deletions api/src/Twig/MappingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
];
}
}
17 changes: 16 additions & 1 deletion api/src/Twig/MappingRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@

use Adbar\Dot;
use CommonGateway\CoreBundle\Service\MappingService;
use CommonGateway\CoreBundle\Service\CacheService;
use Doctrine\ORM\EntityManagerInterface;
use Twig\Extension\RuntimeExtensionInterface;

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;
}

/**
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 346d2d4

Please sign in to comment.