I receive an object during some process and this object needs to figure out its coloring scheme. For example, I have a coloring scheme that is stored like this:
class FirstScheme {
public static $COLORS = array('1' => 'green', '2' => 'red', ...);
}
class SecondScheme {
public static $COLORS = array('1' => 'red', '2' => 'green', ...);
}
I know all the coloring schemes names in advance; they can only change when the code changes. But the coloring scheme to be used for each object needs to be determined at run-time by matching the attribute of this object.
And here I don't know what to do. In python I would define a dict holding the mappings of color schemes to names like this:
d = {'attr_value1': FirstScheme, 'attr_value2': SecondScheme, 'attr_value3': FirstScheme, ...}
And then just access the "COLORS" variable, because every class should have it. But in PHP there is not way to reference a class in a such way, so what is the right way to do it? Note that more than one attribute can map to the same coloring scheme.