XCube_ActionFilter (1)

In this entry, let’s learn about XCube_ActionFilter. ActionFilter is the idea borrowed from mojavi2. If you know not mojavi2 but C or assembly, you may remember the technic that you push function pointers to an array, and call these in order after. ActionFilter is like that techinc. Legacy_Controller creates an instance of various sub-classes of XCube_ActionFilter, and pushes these instances to mFilterChain which is a member property of the controller.

Ok now, see the class design of XCube_ActionFilter. Keep in mind that this design may be changed a little until the regular version of XOOPS Cube.

XCube_ActionFilter has two member functions, which are preFilter() and preBlockFilter(). These two member functions shall be called by Legacy_Controller, at the specific timing. preFilter() is called at the first part of executeCommon() of Legacy_Controller. I call executeCommon() ‘common process’ because it’s like common.php of XOOPS2.

In preFilter(), you can’t use the database instance, because this member function is just first part of the common process. Yes, this member function is called before Legacy_Controller tries to create an instance of the database class.

What is preFilter() used for? You can use it to insert your logic in the first part of the common process. Because Legacy_Controller sets up itself little the instant of preFilter(), the use of preFilter() may be limited. You can use many instances to access resources of XOOPS Cube in preBlockFilter(), but in preFilter() you can’t do it.

Therefore, you may use preFilter() instead of the mainfile.php hack like XoopsProtector. In other words, you may use preFilter() for the logic which is too late if it’s called at the timing of preBlockFilter().

preBlockFilter() is called just before Legacy_Controller begins the preparation of block. preBlockFilter() is convenience, because you can use many functions and many instances in this member function. For example, it’s easy to access the database through the database instance or XoopsObject handlers. Perhaps, preBlockFilter() might be used in 99% of all cases.

Advertisements
This entry was posted in XOOPS Cube. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s