Automattic\WooCommerce\Vendor\GraphQL\Type\Definition

EnumType::serialize │ public │ WC 1.0

Method of the class: EnumType{}

No Hooks.

Returns

null. Nothing (null).

Usage

$EnumType = new EnumType();
$EnumType->serialize( $value );
$value(required)
.

EnumType::serialize() code WC 11.1.2

public function serialize($value)
{
    $lookup = $this->getValueLookup();
    if (isset($lookup[$value])) {
        return $lookup[$value]->name;
    }

    if ($value instanceof \BackedEnum) {
        return $value->name;
    }

    if ($value instanceof \UnitEnum) {
        return $value->name;
    }

    $safeValue = Utils::printSafe($value);
    throw new SerializationError("Cannot serialize value as enum: {$safeValue}");
}