Регистрация одинаковых хуков
Доброго времени!
Есть 4-5 обработок, которые навешиваются на одни и те же хуки. Сейчас это выглядит громоздко:
Как добавить все обработки в «одну» строку? Как-то так:
М.б. есть что правильней? Сделал перебор так:
UPD
Сделал так. 1-4 порядок отображения.
Есть 4-5 обработок, которые навешиваются на одни и те же хуки. Сейчас это выглядит громоздко:
$this->AddHook('template_form_add_topic_photoset_end', 'AddHook1'); $this->AddHook('template_form_add_topic_link_end', 'AddHook1'); $this->AddHook('template_form_add_topic_question_end', 'AddHook1'); $this->AddHook('template_form_add_topic_topic_end', 'AddHook1'); ... $this->AddHook('template_form_add_topic_photoset_end', 'AddHook4'); $this->AddHook('template_form_add_topic_link_end', 'AddHook4'); $this->AddHook('template_form_add_topic_question_end', 'AddHook4'); $this->AddHook('template_form_add_topic_topic_end', 'AddHook4');
Как добавить все обработки в «одну» строку? Как-то так:
$this->AddHook('template_form_add_topic_photoset_end', '_ПЕРЕЧИСЛИТЬ_');
М.б. есть что правильней? Сделал перебор так:
$arrayHook = array("AddHook1", "AddHook2", "AddHook3", "AddHook4"); foreach($arrayHook as $arrayHook){ $this->AddHook('template_form_add_topic_photoset_end', $arrayHook); $this->AddHook('template_form_add_topic_link_end', $arrayHook); $this->AddHook('template_form_add_topic_question_end', $arrayHook); $this->AddHook('template_form_add_topic_topic_end', $arrayHook); }
UPD
Сделал так. 1-4 порядок отображения.
$arrayHook = array( array('AddHook1', 4), array('AddHook2', 3), array('AddHook3', 2), array('AddHook4', 1) ); foreach($arrayHook as $arrayHook){ $this->AddHook('template_form_add_topic_photoset_end', $arrayHook[0],__CLASS__,$arrayHook[1]); $this->AddHook('template_form_add_topic_link_end', $arrayHook[0],__CLASS__,$arrayHook[1]); $this->AddHook('template_form_add_topic_question_end', $arrayHook[0],__CLASS__,$arrayHook[1]); $this->AddHook('template_form_add_topic_topic_end', $arrayHook[0],__CLASS__,$arrayHook[1]); }
2 комментария
можно еще вешать один общий обработчик, а уже из него вызывать другие дочерние