splitbrain/dokuwiki — pull request #362 by roverrobot (2013-10-06 07:06:26+00:00)
Title: New attempt: Refactor actions and split into multiple classes, using a new component mechanism

This is still intended to be a crude attempt to modularize the actions (commands), and mostly aims for attracting discussions.

As with the first attempt, this is based on a new plugin structure called Doku_Component in inc/component.php.
Here I recites the goal of this approach:
* Scripts defined in "inc/components" provide the base classes of various types of components, e.g., actions in the current implementation
* Scripts defined in subdirs of "inc/components" provide implementations of each type of component, e.g., various actions.
* The class name of each component does not need to follow a special pattern, as long as they will not conflict with other classes in Dokuwik
* Auto loading php scripts in "inc/components" directory, recursively
* Only the components that are not inherited by other classes will be used to create an object of the component. This allows easy extension o

This attempt fixed the potential out of order inclusion problem, by include_once the parent class. The advantage of this approach, as I recite below:
* Better seperation of action logics, a Doku_Action class that extends Doku_Component is defined in inc/components/action.php, and various acti
* The actions now are components and thus have their own classes of handlers that provides all the information needed to handle the action.
* Each handler provides the action name that it can perform, and the required permission level for the action, and a handle method.
* If the handle method returns a different action name, a redirection to perform the new action is automatically conducted.
* An action that inherits another action will automatically replace the parent action as the new action handler
* This is the consequence of component inheritence design, but the bad news is that it creates a coveat:
* that _you_ have to make sure that these actions handlers respond to the same action.

Other changes that are made to use the new approach:
* As a result, the more convoluted inc/actions.php is gone
* inc/load.php is changed to stop loading the now nonexisting inc/actions.php
* inc/init.php is changed to make use of inc/component.php, which automatically loads components/action.php and components/actions/*.php
* doku.php is changed to make use to Doku_Action::act($action) method instead of the act_dispatch($act) function

This approach may be extended to modularize other components of dokuwiki, e.g., syntax parsers, events, and renderers.