Skip to content

Support Enums in ->all() filter values #93

@ychedemois

Description

@ychedemois

What problem does your feature request address?

It would be convenient to be able to write code like :

$chargebeeClient->subscription()->all(['status' => ['is' => Status::ACTIVE]])
$chargebeeClient->subscription()->all(['status' => ['is' => $subscription->status])

Currently this produces "Object of class Chargebee\Resources\Subscription\Enums\Status could not be converted to string.",
and we have to explicitly convert to a string :

$chargebeeClient->subscription()->all(['status' => ['is' => Status::ACTIVE->value]])
$chargebeeClient->subscription()->all(['status' => ['is' => $subscription->status->value])

Yet it is very easy to convert a string Enum to a string ;-)

Describe the desired solution

In Util::asString(),
add something like :

if ($value instanceof \Enum && (new \ReflectionEnum($value))->getBackingType()?->getName() === 'string') {
  return $value->value;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions