Closed deni-zen closed 7 years ago
Actually in the Flavor class I should do something like this:
// ...
public static function instance($flavor)
{
if ($flavor instanceof Flavor) return $flavor;
if (is_array($flavor)) return new Flavor($flavor);
if ($flavor instanceof Iterator) {
$flv = array();
foreach ($flavor as $prop => $val) {
$flv[$prop] = $val;
}
return new Flavor($flv);
}
// now throw exception cuz it cant do anything with $flavor
}
And then anywhere that expects a flavor could simply call $flavor = Flavor::instance($flavor);
Implemented and Scrutinized*
I want to accept an associative array containing flavor attributes anywhere that I accept a flavor object. And then internally the array will be converted to a flavor. For instance...
And then internally I would do this: