I have written a standalone service I would like to have executed at the start of every page request in the container without it being referenced by any specific controller in example.
My thinking right now goes in the following direction: Creating a compiler pass:
class SchedulerCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
// always first check if the primary service is defined
if (!$container->has(TestService::class)) {
return;
}
$definition = $container->findDefinition(TestService::class);
// find all service IDs with the app.mail_transport tag
$taggedServices = $container->findTaggedServiceIds('app.service.standalone');
foreach ($taggedServices as $id => $tags) {
$definition->addMethodCall('someFunctionName', arguments);
}
}
}
but the "someFunctionName" function from the service is never called although I have assigned the correct tag to it and the compiler pass is executed correctly and without error.
Am I forgetting something?
OR
Is there a better way to just have this service executed?
Thanks in advance!