The OOP & refactor project weekly report 6

In this week I succeed in decomposing tbl_columns_definition.lib.php, and designed a structure for controller classes. Also, I have done some optimization on the GIS_Visualization.class.php. Now I am working to take logic-controlling codes out from table related scripts (tbl_*.php) to form table controllers.

Files Covered In This Week

  • tbl_columns_definition.lib.php (Decomposed)
  • GIS_Visualization.class.php
  • libraries/controllers

Outcomes In This Week

Decomposing tbl_columns_definition.lib.php
I have decomposed the PMA_getHtmlForColumnAttributes by taking its logic into a new template named “columns_definition/column_attributes”. In this template it handles the generation of $content_cells. Also, other functions that related to PMA_getHtmlForColumnAttributes was converted to templates.

Designing the Controller class
I’d like to introduce a general controller system for PMA, which was designed to handle most of logic in the program. The controller classes was designed with following structure:

Dependency Injection Container

The structure has multiple layers, in each layer it can provide some utility functions or variables that could be accessed in the lower layer. So far I created a Controller class as the base class for any other controllers and it provides $dbi and $response for general usages. And I’d like to create a $request object that helps handling $_REQUEST variable in the future of work.

Also, as the structure diagram shows, I’d like to have a dependency injection container in the future, but it’s likely to become too complex at this moment. So I’m considering whether we could have a better solution for dependency injection.

Last but not least, we should remember that the controllers should be put in libraries/controllers directory and PMA\Controllers namespace. I suggest that we should use namespaces and directories following PSR-4 rules in our future works.

The Problems We Are Facing

Test against the tbl_gis_visualization.php
Today I’ve converted the tbl_gis_visualization.php to the controller form I mentioned above. But I’m not so familiar with GIS data and I can’t find out how to test against the work. Any advice for that are welcomed.

Cleaning up messy structures
Some of codes in our code base is not so friendly 😦
We can see undefined variables (defined in somewhere we would never knows), codes that inline includes and $GLOBALS reference anywhere. We need a better way to clean up them, or it would slow down the refactor process.

A Template Helper
When I was working on tbl_definition_form.inc.php I found that it was directly include in many places. But I couldn’t create template this script because there are too much logic handling codes in it. I think we can create a template helper class only holds static helper functions so that we can easily create template for such kind of scripts.

What Will I Do Next

In this week I will finish constructing Table controllers. A commit with some new controllers will be available soon.

Advertisements
The OOP & refactor project weekly report 6

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