Skip to content

Refactoring

Adham Saad edited this page May 15, 2016 · 4 revisions

Fat Controllers

Almost all of our controllers are getting fat , either a lot of code existing in each action function or there are functions that are not actions inside the controller .

To get over this , we will introduce a new type of models/services in each module called "Workflow" . Workflow class will have 3 main functions

1- init($params) init function will be responsible of initializing the workflow class with required parameters

2- process process function will be responsible of making the main functionalities required by this action ( dealing with the database , sending email ... )

3- prepare prepare function will be responsible of preparing the main data that will be sent to the view . prepare function will be optional as a contorller action can redirect to another action and not display anything .

So , a normal controller action can follow the following example

$workflow = $this->getServiceLocator()->get('ModuleName\Workflow\WorkflowName');

$workflow->init($options)

$workflow->process()

return $workflow->prepare();

Mustache Helpers

Adding helpers to mustache configuration needs to be changed . This is happening now in CustomMustache\Service\RendererFactory::createService .

  • For each helper , a new class will be created following similar to this class ( Translation\Helper\TranslatorHelper )
  • We will add the available helpers ( classes ) in a config array in module.config.php file in CustomMustache . The array will be key to value , while the key is the mustache key and the value is the class name

Replace Phinx with doctrine

We are using Phinx for seeding database , but it lacks a lot of features , and it has a lot of problems It will be good if use doctrine migrations instead , for the seeds and for tracking the database schema changes

ACL

Right now , there are a lot of redundant code mainly in the controllers checking on the roles or the privileges , while this should be achieved through Zend Acl package and CertigateAcl module . We need to add a new Service which have the following static methods

/**
* Checks if the already logged in user has admin role or not 
*/
function isAdmin()

/**
* Check if the already logged in user is able to perform this action or not 
* If $route is null , it will retrieve the current route
*/
function can($route = null)

/**
* Retrieve the details of the logged in user ( id , email ... )
*/
function userDetails()

Open Auth

TBD