Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3924

Symfony 4: Execute standalone service without it being specifically referenced somewhere

$
0
0

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!


Viewing all articles
Browse latest Browse all 3924

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>