php - Installing extensions in homemade CMS -


i've built own cms learning purposes (and fun), expand it, supports basic form of extensions (plugins). work kind of observer-pattern extensions register extensionmanager updates (for example onrendertitle()). every extension consist of 1 mandatory class extensiondata executed every extension in system. extensions register in class using callback (the extensionmanager passed on every extensiondata class).

but every extension has register every page load (because php loses state between every page load), causing potential performance problems.

am doing wrong? or way go? have no experience in writing cms supports extensions (that's i'm trying learn). looked @ how wordpress works extensions, haven't found how loads them up.

plugins in wordpress registered being placed in wp-content/plugins folder, , have have necessary docblocks in main file. convention in wp plugin's main file has same name plugin plus .php extension, e.g. plugins/myplugin/myplugin.php.

as far interaction core of cms goes, can have system fire events , plugins listen them. wp uses actions , filters it. code simple event listener following then:

action('action_name', function() {     // code executed after event fired }); 

your action() function update global array of actions. when want fire event, filter through array of assigned actions.

foreach ($actions['action_name'] $func) {     call_user_func($func); } 

Comments