VipxBotDetectBundle icon indicating copy to clipboard operation
VipxBotDetectBundle copied to clipboard

Add public alias for offering dependency injection

Open beephotography opened this issue 5 years ago • 1 comments

This is more like a question to you, @lennerd: We're currently upgrading from a Symfony 3 application to Symfony 4 and we're using this bundle (is this still under development, because most recent commits are 2 years ago?)

So as we're upgrading, we want to use this bundle via correct dependency injection (not via the container ->get()), but that is not possible without a workaround, as there is no alias to the vipx_bot_detect.detector service ID.

We want to use it via constructor injection (with autowire: true in our service definition):

<?php
use Symfony\Component\HttpFoundation\RequestStack;
use Vipx\BotDetectBundle\BotDetector;

class BotManager
{
    public function __construct(RequestStack $requestStack, BotDetector $botDetector)
    {
        $this->meta = $botDetector->detectFromRequest($requestStack->getCurrentRequest());
    }
}

My workaround to this issue would be to add some

    Vipx\BotDetectBundle\BotDetector:
        alias: vipx_bot_detect.detector
        public: true

to our services.yml but I don't think that this is a good idea.

I'm relatively new to Symfony and I don't know if this is really an issue with your bundle, but I just wanted to go the "quick way" via Github, I hope that's OK for you.

beephotography avatar Apr 08 '20 12:04 beephotography

Hey @beephotography,

thanks for using this bundle! TBH I haven't used Symfony for a very long time and I do not plane to use it in the near feature. Also the list of bots (especially the less popular ones) in this repository might be outdated, so be careful when using it.

But: if you like to improve this bundle for example to be compatible with Symfony 4 feel free to create a PR. Same is true for updating the bot configurations. Would love to see this bundle beeing improved and updated.

Does this answer your questions?

lennerd avatar Apr 11 '20 16:04 lennerd