Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Useful addition to the twigextension #1616

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading