-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate EnumInterface::getName #15
Comments
@J-Ben87 what do you think ? |
I totally agree, I have already been emulating this behaviour for a while:
|
The more I think about it, the more I wonder if this is a good idea. I never tried something like this, but I wonder if this can be even better than what we do already : <?php
use Yokai\EnumBundle\Enum\EnumInterface;
class ConfigurableEnum implements EnumInterface
{
private $name;
private $choices;
public function __construct($name, array $choices)
{
$this->name = $name;
$this->choices = $choices;
}
public function getName()
{
return $this->name;
}
public function getChoices()
{
return $this->choices;
}
} <?php
use Symfony\Component\Translation\TranslatorInterface;
use Yokai\EnumBundle\Enum\AbstractTranslatedEnum;
class ConfigurableTranslatedEnum extends AbstractTranslatedEnum
{
private $name;
private $values;
public function __construct(TranslatorInterface $translator, $transPattern, $name, array $values)
{
parent::__construct($translator, $transPattern);
$this->name = $name;
$this->values = $values;
}
public function getName()
{
return $this->name;
}
public function getValues()
{
return $this->values;
}
} services:
enum.gender:
class: ConfigurableEnum
arguments:
$name: 'member.gender'
$choices:
!php/const:AppBundle\Entity\Member::GENDER_MALE: 'Male'
!php/const:AppBundle\Entity\Member::GENDER_FEMALE: 'Female'
enum.state:
class: ConfigurableTranslatedEnum
arguments:
$translator: '@translator'
$transPattern: 'choice.member.state.%s'
$name: 'member.state'
$values:
!php/const:AppBundle\Entity\Member::STATE_NEW
!php/const:AppBundle\Entity\Member::STATE_VALIDATED
!php/const:AppBundle\Entity\Member::STATE_DISABLED
This require that Enum::getName exists... |
Always the same question: do we want to manipulate classes or configuration? To be honest since constants can be used in yaml both ways seem acceptable to me, however I'm afraid we'll loose PHPStorm navigation feature with the configurable option. Plus keeping constants in domain is not impossible with the current option. |
If that question is coming again and again, meens that there is a debate... So I decided to keep the I consider adding the described generic enum to the bundle source code. |
So, I'm closing this issue, as #24 got a merge request |
An enum already has an identifier : it's class.
Symfony did the same with form types in 2.8.
EnumInterface::getName should be deprecated.
The text was updated successfully, but these errors were encountered: