I use auto_prepend_file in php.ini for this.
It includes a file that has (among others)
and in the index/bootstrap file of projects I have
defined('DEVELOPENT_SERVER') or define('DEVELOPMENT_SERVER', true);
Since you can also set this in the php.ini for CLI, it should also cover cron jobs.
defined('DEVELOPENT_SERVER') or define('DEVELOPMENT_SERVER', false);
It's the easiest way I've been able to come up with so far.
Forgot to mention: I have that auto_prepend_file on dev server(s) only, otherwise the approach doesn't make sense