Hello friends,
Unfortunately I didn’t find any recomendations on how to implement enumerable properties.
A single approch I’ve seen in YII apps is to declare certain class constants and use them
as property values. However, this is not that trivial. Imagine we have TTestManager app
component with it’s enumProperty. Also, there are 2 constants declared in a TTestManager
class:
const EP_VALUE_1 = 1; const EP_VALUE_2 = 2;
This way, our YII configuration might look like one of the following:
'testManager' => array('class' => 'TTestManager', 'enumProperty' => 1)
'testManager' => array('class' => 'TTestManager', 'enumProperty' => TTestManager::EP_VALUE_1)
First case is absolutely unintuitive. Who knows what this ‘1’ actually means?
Second is perfect for low-performance applications. It will load TTestManager class every time
configuration is read.
So, I came to a conclusion that best practice for YII enumerable properties is the following:
const EP_VALUE_1 = 'EP_VALUE_1'; const EP_VALUE_2 = 'EP_VALUE_2';
'testManager' => array('class' => 'TTestManager', 'enumProperty' => 'EP_VALUE_1')
Though this solution is more viable than above mentioned, I still got the feeling of
inventing standards. It’d be great to have some core guide/support for this feature.