I, for my part, like using Entity Constats for a simple relationship. Say, for example, you have an attribute of your object called status , which can only have values ββbetween 0-2. The optional status object may be overflowed in this scenario, so I just define them as constants :
class Entity { const STATUS_PUBLIC = 0; const STATUS_WAITING = 1; const STATUS_REJECTED = 2; }
This allows you to simply check for status versus constants:
$entity->getStatus() == Entity::STATUS_PUBLIC
Or even in a branch:
entity.status == constant('STATUS_PUBLIC', entity)
Or in QueryBuilder :
$builder->andWhere('status = :status') ->setParameter('status', Entity::STATUS_PUBLIC)
It turned out to be quite effective for me.
How to avoid other answers, point to global constants. Use the options for this.
How unclear when to use Parameters :
Adapted from the official best practice :
You cannot create a configuration parameter for a value that you are never going to configure.
You can use parameters, but if these values ββchange. One example would be your application running in multiple environments. Using parameters will give you the opportunity to adapt to environmental changes without updating the code base.
source share