setono / bot-detection-bundle
A Symfony bundle that allows you to test if a user agent is a bot
Installs: 82 344
Dependents: 8
Suggesters: 0
Security: 0
Stars: 7
Watchers: 2
Forks: 2
Open Issues: 5
Type:symfony-bundle
Requires
- php: >=7.4
- setono/symfony-main-request-trait: ^1.0
- symfony/config: ^4.4 || ^5.4 || ^6.0
- symfony/dependency-injection: ^4.4 || ^5.4 || ^6.0
- symfony/http-foundation: ^4.4 || ^5.4 || ^6.0
- symfony/http-kernel: ^4.4 || ^5.4 || ^6.0
- twig/twig: ^2.14 || ^3.4
Requires (Dev)
- infection/infection: ^0.26
- matomo/device-detector: ^5.0 || ^6.0
- matthiasnoback/symfony-dependency-injection-test: ^4.3
- nette/php-generator: ^3.6
- phpbench/phpbench: ^1.2
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.18
- psalm/plugin-symfony: ^4.0
- roave/security-advisories: dev-latest
- setono/code-quality-pack: ^2.2
- symfony/console: ^4.4 || ^5.4 || ^6.0
- symfony/yaml: ^4.4 || ^5.4 || ^6.0
- webmozart/assert: ^1.11
This package is auto-updated.
Last update: 2024-11-18 08:05:52 UTC
README
Detect if the user agent is a bot and act upon it. Under the hood this bundle uses the matomo-org/device-detector, but instead of just using that library this library has a very small subset of user agents that it checks first (i.e. major search engines). This makes it much faster in detecting those very common bots and hence speeds up your request cycle.
Installation
composer require setono/bot-detection-bundle
This installs and enables the plugin automatically if you're using Symfony Flex. If not, add the bundle manually
to bundles.php
.
Usage
You can use the bot detector in your services:
<?php use Setono\BotDetectionBundle\BotDetector\BotDetectorInterface; final class YourService { private BotDetectorInterface $botDetector; public function __construct(BotDetectorInterface $botDetector) { $this->botDetector = $botDetector; } public function yourAction(): void { if ($this->botDetector->isBotRequest()) { // do something to this bot! } // ... } }
and you can use it inside your twig templates:
{% if is_bot_request() %} I knew you where a bot! {% endif %}