@@ -15,6 +15,7 @@ class LDClient {
1515 protected $ _baseUri ;
1616 protected $ _client ;
1717 protected $ _eventProcessor ;
18+ protected $ _offline ;
1819
1920 /**
2021 * Creates a new client instance that connects to LaunchDarkly.
@@ -60,6 +61,10 @@ public function __construct($apiKey, $options = []) {
6061 * @return boolean Whether or not the flag should be enabled, or `default` if the flag is disabled in the LaunchDarkly control panel
6162 */
6263 public function getFlag ($ key , $ user , $ default = false ) {
64+ if ($ this ->_offline ) {
65+ return $ default ;
66+ }
67+
6368 try {
6469 $ flag = $ this ->_getFlag ($ key , $ user , $ default );
6570
@@ -78,6 +83,31 @@ public function getFlag($key, $user, $default = false) {
7883 }
7984 }
8085
86+ /**
87+ * Puts the LaunchDarkly client in offline mode.
88+ * In offline mode, all calls to `getFlag` will return the default value, and `sendEvent` will be a no-op.
89+ *
90+ */
91+ public function setOffline () {
92+ $ this ->_offline = true ;
93+ }
94+
95+ /**
96+ * Puts the LaunchDarkly client in online mode.
97+ *
98+ */
99+ public function setOnline () {
100+ $ this ->_offline = false ;
101+ }
102+
103+ /**
104+ * Returns whether the LaunchDarlkly client is in offline mode.
105+ *
106+ */
107+ public function isOffline () {
108+ return $ this ->_offline ;
109+ }
110+
81111 /**
82112 * Tracks that a user performed an event.
83113 *
@@ -86,6 +116,10 @@ public function getFlag($key, $user, $default = false) {
86116 *
87117 */
88118 public function sendEvent ($ eventName , $ user , $ data ) {
119+ if ($ this ->isOffline ()) {
120+ return ;
121+ }
122+
89123 $ event = array ();
90124 $ event ['user ' ] = $ user ->toJSON ();
91125 $ event ['kind ' ] = "custom " ;
@@ -98,6 +132,10 @@ public function sendEvent($eventName, $user, $data) {
98132 }
99133
100134 protected function _sendFlagRequestEvent ($ key , $ user , $ value ) {
135+ if ($ this ->isOffline ()) {
136+ return ;
137+ }
138+
101139 $ event = array ();
102140 $ event ['user ' ] = $ user ->toJSON ();
103141 $ event ['value ' ] = $ value ;
0 commit comments