Plug-ins

The kernel of Rabbit Framework is a hook engine . When modules requesting a hook, it is the same as publishing an extension point. When registering a hook, it is the same as implementing the extension point. This is exactly a plug-in mechanism.

In fact everything in Rabbit Framework is a plugin to something else previous loaded. The very first thing gets loaded is the Core module, which manages site settings and templates. Pages, Blog, News, User Management and etc. are all plug-ins.

The log below shows the sequence of modules being loaded and hooks being added.

3/5/2011 5:56:14 PM SiteEngine: Start Loading Module Core
3/5/2011 5:56:14 PM SiteEngine:  AddHook getsitesettings
3/5/2011 5:56:14 PM SiteEngine:  AddHook get_layout
3/5/2011 5:56:14 PM SiteEngine:  AddHook get_templates
3/5/2011 5:56:14 PM SiteEngine: Done Loading Module Core

3/5/2011 5:56:14 PM SiteEngine: Start Loading Module Pages
3/5/2011 5:56:14 PM SiteEngine:  AddHook get_homepage
3/5/2011 5:56:14 PM SiteEngine:  AddHook get_menu
3/5/2011 5:56:14 PM SiteEngine:  AddHook save_menu
3/5/2011 5:56:14 PM SiteEngine:  AddHook getmoduleadmin_menu
3/5/2011 5:56:14 PM SiteEngine:  AddHook getpagespage_list
3/5/2011 5:56:14 PM SiteEngine:  AddHook getpagespage
3/5/2011 5:56:14 PM SiteEngine:  AddHook savepagespage
3/5/2011 5:56:14 PM SiteEngine:  AddHook deletepagespage
3/5/2011 5:56:14 PM SiteEngine: Done Loading Module Pages

3/5/2011 5:56:14 PM SiteEngine: Start Loading Module PagesExt
3/5/2011 5:56:14 PM SiteEngine:  AddHook getmoduleadmin_menu
3/5/2011 5:56:14 PM SiteEngine:  AddHook get_menu
3/5/2011 5:56:14 PM SiteEngine:  AddHook getpagespage
3/5/2011 5:56:14 PM SiteEngine:  AddHook getpagespage_editview
3/5/2011 5:56:14 PM SiteEngine:  AddHook getpagespage_createview
3/5/2011 5:56:14 PM SiteEngine:  AddHook get_pagepart
3/5/2011 5:56:14 PM SiteEngine: Done Loading Module PagesExt

3/5/2011 5:56:14 PM SiteEngine: Start Loading Module Testing
3/5/2011 5:56:14 PM SiteEngine:  AddHook get_tests
3/5/2011 5:56:14 PM SiteEngine:  AddHook run_test
3/5/2011 5:56:14 PM SiteEngine: Done Loading Module Testing

3/5/2011 5:56:14 PM SiteEngine: RunHook get_homepage -> 1 Hook
3/5/2011 5:56:14 PM SiteEngine: RunHook get_layout -> 1 Hook
3/5/2011 5:56:14 PM SiteEngine: RunHook getsitesettings -> 1 Hook
3/5/2011 5:56:15 PM Controller: Run Action  -> /
3/5/2011 5:56:15 PM SiteEngine: RunHook GETPagesPage -> 2 Hook
3/5/2011 5:56:15 PM SiteEngine: RunHook GETPagesPage_ItemView -> 0 Hook
3/5/2011 5:56:16 PM SiteEngine: RunHook getsitesettings -> 1 Hook
3/5/2011 5:56:16 PM SiteEngine: RunHook get_menu -> 2 Hook
3/5/2011 5:56:16 PM SiteEngine: RunHook Get_PagePart -> 1 Hook


The request to run hook get_homepage is from the default page. This hook is designed to let a module became the main entry to the site, whether it's a page publishing module or blog module or something else.

In Rabbit Framework hooks are loosely coupled. It is safe to call a hook what has no implementation. Usually the code that calls to run hooks will prepare a default value. In case no one responded to the request, default value is used, like the GETPagesPage_ItemView above.

The hook can be implemented by more than once. The later implementation sees what data previously been created. It decides modified the data or create one data. E.g. the GETPagesPage above, the Pages module loads web page from storage. The PagesExt adds categories information to the web page.

Besides it is no harm to call / run hooks, it is also no harm to register / add hooks. They just sit there doing nothing.

It is a really flexible system. Always remeber the order of loading modules is important. You can configure modules using the Rabbit-Admin page and enable loggin. The logging function helps to debug the hooks. The log file is stored as App_Data\Rabbit\Log.

213938

Last edited Mar 6, 2011 at 2:19 AM by yysun, version 1

Comments

No comments yet.