I'm currently thinking about moving callback functions (for events, pluginhooks, etc) to classes.
My current plugin layout
All the callbacks for plugin hooks can be found in /lib/hooks.php and for events /lib/events.php all other helper functions for my plugin go into /lib/functions.php
This way i can seperate all the functions and know where to look if i need something. It also reduces the size of the individual files thus increasing code readablility.
My new way i want to implement is
Why?
Including files costs time, so try to do this just in time to save on processing time. Also most of the functions in the old system aren't used on every page, but they still need to be parsed.
Doing things in classes may make it easier to test? I don't know this because my plugins don't have tests (yet).
Your thoughts
I would like to hears some views on this point, because it could help in performance/testability but maybe it could hurt in readability/complexity.
Pleae let me know
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Juho Jaakkola@juho.jaakkola

Juho Jaakkola - 0 likes
- Juho Jaakkola@juho.jaakkola

Juho Jaakkola - 0 likes
- Jeroen Dalsem@jdalsem

Jeroen Dalsem - 0 likes
You must log in to post replies.I've started doing/planning the same.
Currently the problem is that hooks and events services give only their own specific stuff (e.g. $hook, $type, $object, $params) as parameters to the handlers. Therefore the handlers need to use global API to access anything not included in the params (e.g. database). This makes it impossible to make unit tests.
Maybe we could modify core to pass services object by default into all handlers? Then we could mock that object in the unit tests.
I've though about almost identical directory structure. Having a good structure makes it much easier to find what you're looking for.
Here I know immediately what each class is doing:
Here I have no idea what each file contains:
Related to the performance gain of moving more "libs" to classes: http://phpixie.com/blog/benchmarking-autoloading-vs-combining-classes-into-a-single-file/