findParameter('ipAddresses', $strategy); if ($whitelistIpAddresses === null) { // kill switch is the reverse of usual feature, meaning if no ip address is defined, assume the kill // switch is active return true; } /** * Here we create a strategy DTO that will be passed to IpAddressStrategyHandler which expects the list of * IPs in the "IPs" parameter. If you want this kill switch to ignore constraints, you can just not pass * them to the transformed strategy */ $transformedStrategy = new DefaultStrategy( $this->getStrategyName(), [ 'IPs' => $whitelistIpAddresses, ], $strategy->getConstraints() ); // here we return the reverse result of ip address strategy handler because we want any whitelisted ip address // to return false meaning the kill switch is not enabled for them return !$this->ipAddressStrategyHandler->isEnabled($transformedStrategy, $context); } } $unleash = UnleashBuilder::create() ->withAppName($appName) ->withAppUrl($appUrl) ->withInstanceId($instanceId) ->withHeader('Authorization', $apiKey) ->withStrategy(new KillSwitchStrategyHandler(new IpAddressStrategyHandler())) // add our custom strategy ->build(); if ($unleash->isEnabled('myAppKillSwitch')) { echo "Kill switch is enabled, exiting", PHP_EOL; exit(); } echo "Kill switch not enabled, cool!", PHP_EOL;