Welcome Guest, Not a member yet? Register   Sign In
trigger_events in IonAuth ?
#1

[eluser]solid9[/eluser]
Hi guys

I'm trying to understand IonAuth Trigger_event method.

Code:
public function trigger_events($events)
{
if (is_array($events) && !empty($events))
{
  foreach ($events as $event)
  {
   $this->trigger_events($event);
  }
}
else
{
  if (isset($this->_ion_hooks->$events) && !empty($this->_ion_hooks->$events))
  {
   foreach ($this->_ion_hooks->$events as $name => $hook)
   {
   $this->_call_hook($events, $name);
   }
  }
}
}

Can someone explain to me in simple english what the method do?

Thanks in advanced.




#2

[eluser]solid9[/eluser]
What is the purpose of this method?
#3

[eluser]Matteo[/eluser]
Ion_Auth uses this function to call and set various custom functions through CI's hooks feature. Take a look at the previous 4 functions in the model.

Code:
public function set_hook($event, $name, $class, $method, $arguments)
{
  $this->_ion_hooks->{$event}[$name] = new stdClass;
  $this->_ion_hooks->{$event}[$name]->class     = $class;
  $this->_ion_hooks->{$event}[$name]->method    = $method;
  $this->_ion_hooks->{$event}[$name]->arguments = $arguments;
}

public function remove_hook($event, $name)
{
  if (isset($this->_ion_hooks->{$event}[$name]))
  {
   unset($this->_ion_hooks->{$event}[$name]);
  }
}

public function remove_hooks($event)
{
  if (isset($this->_ion_hooks->$event))
  {
   unset($this->_ion_hooks->$event);
  }
}

protected function _call_hook($event, $name)
{
  if (isset($this->_ion_hooks->{$event}[$name]) && method_exists($this->_ion_hooks->{$event}[$name]->class, $this->_ion_hooks->{$event}[$name]->method))
  {
   $hook = $this->_ion_hooks->{$event}[$name];

   return call_user_func_array(array($hook->class, $hook->method), $hook->arguments);
  }

  return FALSE;
}

I don't pretend to fully understand everything that is going on here, but he uses it extensively throughout the code.
#4

[eluser]nnolting[/eluser]
It seems like a really cool feature, although I have not been able to get it to work and the example in the documentation http://benedmunds.com/ion_auth/#trigger_events don't really show a good example of how the triggers that are in the ion auth model are supposed to be used. I wish there was a good example in the controller.
#5

[eluser]adityamenon[/eluser]
It doesn't look like this system is related to CI's main hooks at all! Ion auth seems to have evolved a mini-hook environment of it's own.
#6

[eluser]adityamenon[/eluser]
I did not look at the documentation for set_hook() : here's a gist explaining more: https://gist.github.com/657de89b26decda2b2fa
#7

[eluser]adityamenon[/eluser]
This is recommended reading http://benedmunds.com/ion_auth/#set_hook
#8

[eluser]jmadsen[/eluser]
A little late to the party, but I have been doing a little work with Ion Auth lately & wrote this up explaining the use of hooks

http://www.codebyjeff.com/blog/2013/01/u...h-ion_auth




Theme © iAndrew 2016 - Forum software by © MyBB