I want to use backed enums in my CakePHP project like so:
enum ArticleStatus: int
{
case DRAFT = 1;
case PUBLISHED = 2;
}
$article = $this->Articles->find()->where(['status' => ArticleStatus::DRAFT])->first();
However, Cake expects type int
and not ArticleStatus
. The same problem occurs when I try to patch an entity using an enum.
I understand that I could use the enum’s value
property, but that seems somewhat verbose and error-prone. Is there a way for Cake to accept the enum type or automatically coerce it?