public static function collect_models(Jam_Model $model, array $children = array()) { $collection = array($model); foreach ($children as $child_name => $child_children) { if (is_numeric($child_name)) { $collection = array_merge($collection, Jam_Behavior_Cascade::_models($model->{$child_children})); } else { foreach (Jam_Behavior_Cascade::_models($model->{$child_name}) as $child_item) { $collection = array_merge($collection, Jam_Behavior_Cascade::collect_models($child_item, (array) $child_children)); } } } return $collection; }