The OOP & refactor project weekly report 7

During the last week I finished my work on the dependency injection container and a helper for the template system. Also, the mid-term evaluation was submitted. I am grateful of being one of the PMA developers 🙂

Files Covered In This Week

  • libraries/ArrayHelper.class.php
  • libraries/tbl_columns_definition_form.inc.php
  • libraries/di/*

Outcomes In This Week

The helper for template system & Refactor tbl_columns_definition_form.inc.php
In order to refactor tbl_columns_definition_form.inc.php, I created this helper to simplify branching and accessing array elements. By using PMA\Util\get, it enable us access an array using dot notation. Here is an example:


require_once 'libraries/util.lib.php';
use PMA\Util;
$test = array('a' => array('b' => array('c')));
echo Util\get($test, 'a.b');

It will print the result below:

c

If the specified path or the value not exist, it will return a default value. The default value can be set as the third parameter of the function. It’s set to null by default.

Dependency Injection Container
First I implemented the container using closures, but phpunit failed so that I can only implement a new one in class form. The dependency container is mainly use to free us from passing plenty of parameters to construct classes.

When we use the container, we can just set up some global parameters like $GLOBAL['dbi'] and $GLOBAL['url_query'] in it. We can also register services or factories (Container::factory and Container::service). After we finish setting up dependencies, we can construct the class by calling Container::get and pass the rest of user-specified parameters for the class. We don’t need to worry about the long-long parameter list, since the container will resolve by itself.

What Will I Do Next

In the following 1 weeks, I will work on refining the Table class and TableSearch class.

Advertisements
The OOP & refactor project weekly report 7

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