-
Notifications
You must be signed in to change notification settings - Fork 1
Porting Guide
As of version 2.3.0, the preferred method for integrating Bad Behaviour into a new platform is by implementing the BadBehaviour\Core\HostAdapterInterface. This modern OOP approach replaces the old method of hooking global callback functions.
If you simply want to drop Bad Behaviour into a custom PHP project without database logging, you can use the included GenericAdapter out of the box:
require 'vendor/autoload.php';
use BadBehaviour\Core\BadBehaviour;
use BadBehaviour\Core\Adapter\GenericAdapter;
$adapter = new GenericAdapter();
$bb = new BadBehaviour($adapter);
$bb->run();Please note that Bad Behavior relies on its database logging for some parts of its spam protection, and thus will run in a degraded mode when no logging is available.
To add Bad Behaviour to a new platform (e.g., a custom CMS, Laravel, Symfony, etc.), you simply create a class that implements BadBehaviour\Core\HostAdapterInterface. This bridges the core library with your platform's database and settings.
Please refer to the Writing a Custom Adapter page for a complete, step-by-step tutorial and an example of how to build an adapter.
If you maintain an existing port that used the pre-2.3.0 procedural method—where you modified bad-behaviour-generic.php and defined global functions like bb2_db_query(), bb2_db_escape(), bb2_insert(), and bb2_read_settings()—your existing code will still work.
The legacy bootstrap files (bad-behaviour-generic.php, bad-behaviour-mediawiki.php, etc.) have been converted into backward-compatible shims. They automatically detect the environment, instantiate the new OOP classes internally, and route the old global function calls to the appropriate Adapter classes.
However, global function overrides for settings and database hooks have been deprecated in favor of the OOP HostAdapterInterface. You are highly encouraged to migrate your custom port to an Adapter class for future compatibility.