Advice on refactoring PHP Project

Posted by b0x on Programmers See other posts from Programmers or by b0x
Published on 2014-06-10T05:53:14Z Indexed on 2014/06/10 15:40 UTC
Read the original article Hit count: 246

Filed under:
|
|
|

I have a small SAS ERP that was written some years ago using PHP.

At that time, it didn't use any framework, but the code isn't a mess.

Nowadays, the project grows and I’m now working with 3 more programmers.

Often, they ask to me why we don’t migrate to a framework such as Laravel.

Although I'd love trying Laravel, I’m a small business and I don't have time nor money to stop and spend a whole year building everything from scratch. I need to live and pay the bills.

So, I've read a lot about this matter, and I decided that doing a refactoring is the best way to do it.

Also, I'm not so sure that a framework will make things easy.

Business goals are:

  • Make the code easier to new hired programmers

  • Separate the "view", in order to:

    • release different versions of this product (using the same code), but under different brands and websites at the minimum cost (just changing view)

    • release different versions to fit mobile/tablet.

  • Make different types of this product, selling packages as if they were plugins.

  • Develop custom packages for some costumers (like plugins/addon's that they can buy to put on the main application).

Code goals:

  • Introduce best pratices, standards for everyone

  • Try to build my own MVC structure

  • Improve validation of data/forms (today they are mixed in both ajax and classes)

  • Create automated testing routines for quality assurance.


My current structure project:

  • class\
  • extra\
  • hd\
  • logs\
  • public_html\
  • public_html\includes\
  • public_html\css|js|images\

class\

There are three types of classes.

They are all “autoloaded” with something similar with PSR-0, but I don’t use namespaces.

1. class.Something.php

Connects to Database using specific methods. I.e: Costumer->list();

It uses “class.Db.php”, that it’s an abstraction of mysql on every method.

2. class.SomethingProc.php

Do things that “join” things that come from “class.Something.php”. Like IF/ELSE, math operations.

3. class.SomethingHTML.php

The classes with “HTML” suffix implements only static methods and HTML code only.

A real life example:

All the programmers need to use $cSomething ($c to class) and $arrSomething (to array).

Costumer.php (view)

<?php
$cCosumter = new Costumer();
$arrCostumer = $cCostumer->list();
echo CostumerHTML::table($arrCostumer);
?>

Extra\

Store 3rdparty projects/classes from others, such MPDF, PHPMailer, etc.

Hd\

Store user’s files outsite wwwroot dir.

Logs\

Store phplogs and the system itself logs

(We have a static Log::error() method, that we put in every method of every class)

Public_html\

Stores the files that people use.

Public_html\includes\

Store the main “config.php” file and all files that do “ajax things” ajax.Costumer.php, for example.

Help is needed ;)

So, as you can see we have some standards, and also for database things.

But I want to write a manual of our rules. Something that I can give to any new programmer at my company and he can go on.

This is not totally a mess, but it could be better seeing the new practices.

What could I do to separate this as MVC, to have multiple views.

Could you give me some tips considering my goals? Keep im mind the different products/custom things for specific costumers without breaking the main application.

URL for tutorials, books, etc, would be nice.

© Programmers or respective owner

Related posts about php

Related posts about mvc