Skip to content

Instantly share code, notes, and snippets.

@carlosocarvalho
Created September 13, 2016 15:33
Show Gist options
  • Save carlosocarvalho/4aaa0f7476c60ce2ec8f9c9ddfeb9fcf to your computer and use it in GitHub Desktop.
Save carlosocarvalho/4aaa0f7476c60ce2ec8f9c9ddfeb9fcf to your computer and use it in GitHub Desktop.
<?php
class RegisterEventAutoload{
/**
* [handler on start classe events
* @return [type] [description]
*/
public function handler(){
$ci = get_instance();
$ci->load->config('register_events', true);
$registered = config_item('register_events');
if(! $registered) return;
$this->registerAllEvents($registered);
}
/**
* [registerAllEvents description]
* @param [type] $events [description]
* @return [type] [description]
*/
private function registerAllEvents($events){
foreach ($events as $key => $ev) {
foreach ($ev as $classEvent) {
if(!is_object($classEvent))
$classEvent = new $classEvent();
Events::register($key , [$classEvent , 'handler']);
}
}
}
}
//** hooks/RegisterEventAutoload.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment