Welcome Guest, Not a member yet? Register   Sign In
Khaos :: KhEvent
#21

[eluser]Avatar[/eluser]
When I register an event It registers throughout my app? I can trigger it from anywhere once I register it someplace? Since it get attached to &$this or do I even have to register the event? can I just trigger it? What are some of the best ways I can use this lib? I see the power that it has, just not sure how to consume it as of yet. Thank you.
#22

[eluser]Majd Taby[/eluser]
I've bundled this Event manager with CodeExtinguisher and it's amazing.
I have a global class which handles my events, called CodexEvents. In my code, I can trigger an event anywhere in code, and pass it w/e data I want. For example, for CodeExtinguisher, i have a trigger that gets triggered before/after information is inserted, edited and deleted. Also when a user logs in, etc etc.

It adds a nice layer of separation...not to mention it actually works.
#23

[eluser]Neophyte[/eluser]
Im looking to make KhEvent a bit more dynamic in the way it loads its observers the 2 approaches ive been considering are as follows.

Groups:
When you trigger an event you can optionally specify a group eg. $this->event->trigger('onLogin', array('username', 'password'), 'auth'); this would result in all files within the auth subfolder being loaded if they were not already loaded.

Mapping:
A map of all the events which have listeners is created so when an event is triggered any observers which arent currently loaded but which have methods correlating to said event will be automatically loaded before the dispatching of the event. (obviously the map would be cached)

Im just looking to see if anyone has any opinions/preferences on the above approaches or any alternative approaches worth considering.
#24

[eluser]wiredesignz[/eluser]
Mapping sounds more flexible, and if it can be altered dynamically once loaded would be even better.
#25

[eluser]Neophyte[/eluser]
ChangeLog - KhEvent - 0.2

Library name changed from 'event' to 'khevent' though for backwards compatability the library can still be called using 'event' from the CI super object.

Observer Map implemented so you no longer need to add your observers to the config file instead they will be automagically loaded as and when needed.

New config option 'autoscan' has been added, when set to true the observer map is automatically rebuilt when a file in the observers directory is changed when set to false you need to manually delete the 'kh_event_map' file from the cache folder when you change an observer. General this would be the difference between development and live versions of the site as when the site goes live the observers directory should remain the same.

As always any bugs let me know Smile
#26

[eluser]wiredesignz[/eluser]
Good work Neophyte, I will definitely give this a run. Wink
#27

[eluser]wiredesignz[/eluser]
Thanks for this contribution Neophyte.

I have discovered a small problem running under Windows/Apache/PHP5 where the event name is being added to the map at line 450 (map[onPostController][] = ), but when triggered the event name is converted to lowercase at line 343 and tested as (isset map[onpostcontroller]) which will fail of course.

I have altered line 450 to force lowercase map elements:
Code:
$this->_map[strtolower($method)][] =
Can you forsee any problems with this?
#28

[eluser]Neophyte[/eluser]
@wiredesignz - nice catch that fix should work fine and shouldnt impact on any other code. with working on php4 at the momment i forgot php5 returns the original case. sorry for the slow reply :o been busy sorting stuff out for moving house.
#29

[eluser]Majd Taby[/eluser]
just wanted to let you know that the khaos plugins.php file in hooks/ is hardcoded to look for the library in APPPATH which means that the script breaks when you move your libraries to the system/libraries/ directory.

Just thought i'd let you know because people assume that you can move libraries between system/ and application/
#30

[eluser]adwin[/eluser]
is this same with the one in Wordpress ?

ah .. that would be wonderfull ... I wish I knew this before ... because I needed for my project Wink




Theme © iAndrew 2016 - Forum software by © MyBB