Skip to content

Instantly share code, notes, and snippets.

@pragmaticivan
Created May 18, 2011 14:33
Show Gist options
  • Save pragmaticivan/978689 to your computer and use it in GitHub Desktop.
Save pragmaticivan/978689 to your computer and use it in GitHub Desktop.
Possibilidade de array no only e except para as before actions
/**
* Executa os métodos adicionados no before e after action.
*
* @param array $methods
* @return void
*/
private function execute_methods($methods) {
foreach ($methods as $key => $value) {
if (is_array($value)) {
if (isset($value['only'])) {
if (is_array($value['only'])) {
foreach ($value['only'] as $only) {
if ($this->request->action_name === $only) {
call_user_func(array($this,$key));
}
}
} else {
if ($this->request->action_name === $value['only']) {
call_user_func(array($this,$key));
}
}
} elseif(isset($value['except'])) {
if (is_array($value['except'])) {
foreach ($value['except'] as $except) {
if ($this->request->action_name !== $except) {
call_user_func(array($this,$key));
}
}
} else {
if ($this->request->action_name !== $value['except']) {
call_user_func(array($this,$key));
}
}
}
} else {
call_user_func(array($this,$value));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment