•  » Engine
  •  » trigger_action, trigger_event : differences ?

#1 2011-06-24 19:17:54

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

trigger_action, trigger_event : differences ?

I'm sure many developpers wonder what is the real difference between these two functions, that are the main functions of the core ^^

I know that trigger_event returns the var $data but, except that, they are almost identical, so why two functions ?

It appears that we use trigger_action to detect a precise point of the core, although trigger_event is used to compute datas but looking at the prototype

function trigger_action (string $event [, mixed $data=null ] )

also accept more arguments

rvelices this is for you ! :-)

Last edited by mistic100 (2011-06-24 19:22:00)

Offline

 

#2 2011-06-24 21:13:20

rvelices
Former Piwigo Team
2005-12-29
1960

Re: trigger_action, trigger_event : differences ?

mistic100 wrote:

I know that trigger_event returns the var $data but, except that, they are almost identical, so why two functions ?

Well, this is enough. No ? Also note that in the case of an event, the $data might change as it goes through the handlers. In the second case it is going to be the same...

Offline

 

#3 2011-06-24 21:17:55

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: trigger_action, trigger_event : differences ?

rvelices wrote:

Well, this is enough. No ?

yeah, but for that we don't need two functions, we can call strtotime without print the result

and each time trigger_action is called, no $data is given (that's not a rule but a fact)...

Last edited by mistic100 (2011-06-24 21:24:28)

Offline

 

#4 2011-06-25 17:29:35

P@t
Piwigo Team
Nice
2007-06-13
4098

Re: trigger_action, trigger_event : differences ?

mistic100 wrote:

yeah, but for that we don't need two functions, we can call strtotime without print the result

I don't understand...

mistic100 wrote:

and each time trigger_action is called, no $data is given (that's not a rule but a fact)...

In admin/batch_manager_global.php, you have:

Code:

trigger_action('element_set_global_action', $action, $collection);

I added this to trigger actions on batch manager with thumbnails regeneration and websize regeneration...
We don't need trigger_event here, but trigger action...


P@t

Offline

 

#5 2011-06-25 17:35:08

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: trigger_action, trigger_event : differences ?

P@t wrote:

mistic100 wrote:

yeah, but for that we don't need two functions, we can call strtotime without print the result

I don't understand...

I just want to say that the only fact that a function returns something and the other doesn't not require two differents functions

P@t wrote:

mistic100 wrote:

and each time trigger_action is called, no $data is given (that's not a rule but a fact)...

In admin/batch_manager_global.php, you have:

Code:

trigger_action('element_set_global_action', $action, $collection);

ok, so what append here if we use trigger_event ?

I don't want to change the code, it works fine, I want to understand why there is two functions...

Offline

 

#6 2011-06-25 20:14:56

P@t
Piwigo Team
Nice
2007-06-13
4098

Re: trigger_action, trigger_event : differences ?

mistic100 wrote:

Code:

trigger_action('element_set_global_action', $action, $collection);

ok, so what append here if we use trigger_event ?

If you use a trigger_event here, your plugin need to return $action for other plugins.

It's not the same usage... so it's clearer to have two different functions, isn't it?


P@t

Offline

 

#7 2011-06-25 20:26:40

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: trigger_action, trigger_event : differences ?

okay !! I understand
we can say that with 'trigger_event' events are in series, and with 'trigger_action' events are parralels (its minded : in PHP all is in serie)

Offline

 

#8 2011-06-25 20:37:23

P@t
Piwigo Team
Nice
2007-06-13
4098

Re: trigger_action, trigger_event : differences ?

rvelices wrote:

Also note that in the case of an event, the $data might change as it goes through the handlers. In the second case it is going to be the same...

:-)))

Note that with trigger_action, events are not really "in parallel", events are still loaded with the priority parameter (default 50).


P@t

Offline

 
  •  » Engine
  •  » trigger_action, trigger_event : differences ?

Board footer

Powered by FluxBB