# 기능 플래그 결정

기능 플래그는 켜짐(on) 상태와 꺼짐(off) 상태가 있습니다. 각 상태에 따라 다른 기능을 설정하게 됩니다.\
기능 플래그를 적용한 기능에 어떤 사용자가 접근할 경우 켜짐 혹은 꺼짐 상태를 받을 수 있어야 합니다. 이 상태 결정을 핵클 SDK를 통해 진행할 수 있습니다.

## isFeatureOn

`isFeatureOn()` 메소드에 **기능 키**를 전달하면 사용자에 대한 상태 결과를 전달받을 수 있습니다. 이후 상태에 따른 로직을 구현합니다.

아래 예제 코드에서는 기능 키 42를 전달하고 있으며, 상태를 받을 사용자의 사용자 식별자는 "ae03e1adf" 입니다.

```php
<?php
  
require 'vendor/autoload.php';

$client = \Hackle\HackleClients::create("YOUR_SERVER_SDK_KEY");

$user = \Hackle\Common\HackleUser::builder()
    ->deviceId("ae2182e0")
    ->build();

$isFeatureOn = $client->isFeatureOn(42, $user);

if ($isFeatureOn) {
    // ON 기능
} else {
    // OFF 기능
}

?>
```

## featureFlagDetail

`featureFlagDetail()` 메소드는 `isFeatureOn()` 메소드와 동일하게 동작하고 추가로 상태 결정에 대한 사유를 같이 제공합니다. 수동할당이 잘 되고 있는지 알아보거나 설정한 트래픽 할당 대비 결과 비중이 이상하다고 여길 때 유용하게 활용할 수 있습니다.

파라미터로 기능 키를 전달해야 합니다. 아래 예제 코드의 경우 기능 키 42를 전달하고 있습니다.

```php
<?php
  
require 'vendor/autoload.php';

$client = \Hackle\HackleClients::create("YOUR_SERVER_SDK_KEY");

$user = \Hackle\Common\HackleUser::builder()
    ->deviceId("ae2182e0")
    ->build();

$featureFlagDecision = $client->featureFlagDetail(42, $user);

// 기능 on/off 여부
$isOn = $featureFlagDecision->isOn();

// 상태 결정 사유
$reason = $featureFlagDecision->getReason();

?>
```

상태 결정 사유는 **`SDK_NOT_READY`** 와 같은 형태로 받게 됩니다. 자세한 내용은 아래 표를 참고해주세요.

<table><thead><tr><th width="233.71875">결정 사유</th><th width="370.8046875">설명</th><th>분배 결과</th></tr></thead><tbody><tr><td><code>SDK_NOT_READY</code></td><td>SDK 사용 준비가 되지 않았습니다.<br>(예: 잘못된 SDK 키로 초기화 시도)</td><td>기본 상태<br>(꺼짐/off)</td></tr><tr><td><code>FEATURE_FLAG_NOT_FOUND</code></td><td>전달한 기능 키에 대한 기능 플래그를 찾을 수 없습니다.<br>기능 키가 잘못되었거나 해당 기능 플래그가 보관 상태일 수 있습니다.</td><td>기본 상태<br>(꺼짐/off)</td></tr><tr><td><code>FEATURE_FLAG_INACTIVE</code></td><td>기능 플래그가 꺼짐 상태입니다</td><td>기본 상태<br>(꺼짐/off)</td></tr><tr><td><code>INDIVIDUAL_TARGET_MATCH</code></td><td>개별 타겟팅에 매치 되었습니다.</td><td>개별 타겟팅으로<br>설정한 상태</td></tr><tr><td><code>TARGET_RULE_MATCH</code></td><td>사용자 타겟팅에 매치 되었습니다.</td><td>사용자 타겟팅으로 설정한 상태</td></tr><tr><td><code>DEFAULT_RULE</code></td><td>개별 타겟팅, 사용자 타겟팅 중 어디에도 매치 되지 않았습니다.</td><td>기본 룰로<br>설정한 상태</td></tr><tr><td><code>EXCEPTION</code></td><td>알 수 없는 오류가 발생했습니다.</td><td>기본 상태<br>(꺼짐/off)</td></tr></tbody></table>

## 기능 플래그 파라미터

* `featureFlagDetail()` 메소드를 통해 상태 결정에 대한 파라미터 값도 같이 제공받을 수 있습니다.
* 핵클의 기능 플래그 화면에서 설정한 파라미터 값이 key, value 형태로 존재하기 때문에, 설정한 파라미터 유형에 따라 아래 메소드를 사용하여 설정한 파라미터 값을 받아 활용할 수 있습니다.
* 기능 플래그의 파라미터 설정화면에서 값을 유동적으로 변경할 수 있습니다.

### getString

* STRING, JSON 유형으로 설정된 파라미터 값을 반환합니다.
* 상태 결정에 따라 기본 값 혹은 규칙에 설정된 값을 반환합니다.

```php
<?php
  
require 'vendor/autoload.php';

$client = \Hackle\HackleClients::create("YOUR_SERVER_SDK_KEY");

$user = \Hackle\Common\HackleUser::builder()
    ->deviceId("ae2182e0")
    ->build();

$featureFlagDecision = $client->featureFlagDetail(42, $user);

$strValue = $featureFlagDecision->getString("parameter_key_string_type", "defaultValue");
$jsonValue = $featureFlagDecision->getString("parameter_key_json_type", "defaultValue");
  
?>
```

### getInt

* Number 유형으로 설정된 parameter 값을 Int 타입으로 반환합니다.
* 상태 결정에 따라 기본 값 혹은 규칙에 설정된 값을 반환합니다.

```php
<?php
  
require 'vendor/autoload.php';

$client = \Hackle\HackleClients::create("YOUR_SERVER_SDK_KEY");

$user = \Hackle\Common\HackleUser::builder()
    ->deviceId("ae2182e0")
    ->build();

$featureFlagDecision = $client->featureFlagDetail(42, $user);

$intValue = $featureFlagDecision->getInt("parameter_key_number_type", 0);

?>
```

### getFloat

* Number 유형으로 설정된 parameter 값을 float 타입으로 반환합니다.
* 상태 결정에 따라 기본 값 혹은 규칙에 설정된 값을 반환합니다.

```php
<?php
  
require 'vendor/autoload.php';

$client = \Hackle\HackleClients::create("YOUR_SERVER_SDK_KEY");

$user = \Hackle\Common\HackleUser::builder()
    ->deviceId("ae2182e0")
    ->build();

$featureFlagDecision = $client->featureFlagDetail(42, $user);

$floatValue = $featureFlagDecision->getFloat("parameter_key_number_type", 0.0);

?>
```

### getBool

* Boolean 유형으로 설정된 parameter값을 반환합니다.
* 상태 결정에 따라 기본 값 혹은 규칙에 설정된 값을 반환합니다.

```php
<?php
  
require 'vendor/autoload.php';

$client = \Hackle\HackleClients::create("YOUR_SERVER_SDK_KEY");

$user = \Hackle\Common\HackleUser::builder()
    ->deviceId("ae2182e0")
    ->build();

$featureFlagDecision = $client->featureFlagDetail(42, $user);

$boolValue = $featureFlagDecision->getBool("parameter_key_bool_type", true);

?>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hackle.io/development-guide/php/php-feature-flag.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
