<?phpdeclare(strict_types=1);namespaceDrush\Listeners;useDrush\AttributesasCLI;useDrush\Boot\DrupalBootLevels;useDrush\Event\ConsoleDefinitionsEvent;usePsr\Log\LoggerInterface;useSymfony\Component\Console\Event\ConsoleCommandEvent;useSymfony\Component\Console\Input\InputOption;useSymfony\Component\EventDispatcher\Attribute\AsEventListener;/** * To temporarily use this Listener, use the --include option - e.g. `drush --include=/path/to/drush/examples updatedb` */#[AsEventListener(method:'onDefinitions')]#[AsEventListener(method:'onSqlSyncConsoleCommand')]#[AsEventListener(method:'onRSyncConsoleCommand')]#[AsEventListener(method:'onUpdateDbCommand')]#[CLI\Bootstrap(level:DrupalBootLevels::NONE)]finalclassPolicyListener{use\Drush\Commands\AutowireTrait;publicfunction__construct(protectedLoggerInterface$logger,){}publicfunctiononSqlSyncConsoleCommand(ConsoleCommandEvent$event):void{if($event->getCommand()->getName()=='sql:sync'){$input=$event->getInput();if($input->getArgument('target')=='@prod'){$this->logger->error('Per {file}, you may never overwrite the production database.',['file'=>__FILE__]);$event->disableCommand();}}}publicfunctiononRSyncConsoleCommand(ConsoleCommandEvent$event):void{if($event->getCommand()->getName()=='rsync'){if(preg_match("/^@prod/",$event->getInput()->getArgument('target'))){$this->logger->error('Per {file}, you may never rsync to the production site.',['file'=>__FILE__]);$event->disableCommand();}}}publicfunctiononUpdateDbCommand(ConsoleCommandEvent$event):void{if($event->getCommand()->getName()=='updatedb'){if(!$event->getInput()->getOption('secret')=='mysecret'){$this->logger->error('UpdateDb command requires a secret token per site policy.');$event->disableCommand();}}}publicfunctiononDefinitions(ConsoleDefinitionsEvent$event):void{$event->getApplication()->get('updatedb')->addOption(name:'secret',mode:InputOption::VALUE_REQUIRED,description:'A required token else user may not run updatedb command.');}}