DooPHP – How To Decouple PROTECTED_FOLDER To Make Your Protected Folder Outside Your Public/Web Root Folder

Remark: Before actually going into the subject title, I’ll make a small intro/apercu of DooPHP.

What Is DooPHP?

DooPHP is a light-weight PHP framework, which claims to be one of the fastest MVC framework (blazing fast), if not the current fastest PHP MVC framework around right now; according to this benchmark carried out by Leng Sheng Hong
– Leng is the father of DooPHP.

DooPHP According To Me

It’s been like a couple of weeks now since I’m playing around with DooPHP. Before using it for a project, I usually see how far the framework can get me going concerning flexibility, efficiency and strength. I was quite surprised with this framework actually. It has some nice modules inside with some good thoughts; it’s overall performance, the way it implements its MVC skeleton, the routing mechanism and also the HTTP_AUTHORIZATION scheme which is a very rare implementation. Leng Sheng Hong definitely shows some great concept at work, impressive!

The Not So Good Part

As with any framework, there’s bound to be some not-so-nice parts:
1) It does not make use of the Autoloading flexibility which PHP 5.x offers. Too many encapsulated includes/require. For example, the method call [Doo::loadCore(‘foo’);] simply calls an include for ‘foo‘. The version in their trunk does provide a block of code which directly overrides the magic method __autoloadI don’t agree with such an approach since this hinders the system to coexist with other autoloads when you might need to plug-in some other independent modules.

2) the templating system and the DB layer are surely not the best one right now.

3) It’s ‘PROTECTED_FOLDER’ is too tightly coupled!

I have had a little discussion with one of the community developer there, namely Richard. It seems that those points coupled with some other foreseeable issues, are currently being debated among the actual group of developers/contributers. Issues 1) and 2) should be addressed in later versions.

How I See the Current Implementation Of Their PROTECTED_FOLDER

What I observed was:
– Most files include the proctected folder in the fashion:
“self::conf()->SITE_PATH .’protected/FOLDER/Some_class_name.php'”.
Why not something like “self::conf()->PROTECTED_FOLDER.’/someFolders/Some_class_name.php'” ?

Leng told me that this issue has already been resolved as he tried to explain in his article here. BUT I don’t seem to agree at all with his solution because he was still using require_once(Doo::conf()->SITE_PATH.Doo::conf()->PROTECTED_FOLDER.”controller/{$routeRs[0]}.php”);
Why not directly use require_once(Doo::conf()->PROTECTED_FOLDER . “controller/{$routeRs[0]}.php”); ?

How To Decouple PROTECTED_FOLDER To Make Your Protected Folder

This is one solution to fit what I was trying to do; to remove the protected folder outside my root folder for my current (single) project. Actually, why not allow user to define the PROTECTED_FOLDER if the protected is outside the default place and/or is being renamed and use it directly in the code !? Make sense, right? Thus no fuss for the code to find the actual path of PROTECTED_FOLDER.

Here’s how I did it:

1) in index.php, I define: $config['SITE_PATH']

$config['SITE_PATH'] = dirname(__FILE__) . '/'; //TODO: may be use DIRECTORY_SEPARATOR instead of the '/'
include '../protected/config/common.conf.php';
include '../protected/config/routes.conf.php';
//etc...

2)  in common.conf.php, I define: $config['PROTECTED_FOLDER']

$config['PROTECTED_FOLDER'] = str_replace('app', 'protected', str_replace('app', 'protected', $config['SITE_PATH']));

3)  Everywhere in the project I made the following substitution

Replace Doo::conf()->SITE_PATH . Doo::conf()->PROTECTED_FOLDER with Doo::conf()->PROTECTED_FOLDER

7 class files concerned as follows:
- dooframework/app/DooWebApp.php
- dooframework/app/DooSiteMagic.php
- dooframework/Doo.php
- dooframework/view/DooViewBasic.php
- dooframework/view/DooView.php
- dooframework/cache/DooFrontCache.php
- dooframework/cache/DooFileCache.php

With the changes above, I have a directory structure as:

==> /someRootFolder/
=======> app - [global]
=======> proctected [controller, view, model, cache..etc]
=======> dooframework [..]

This works the way it should have been if I just wanted to move proctected outside app.

Downside Of My Approach

Richard pointed out my approach would not work if he wanted to have multiple projects and hence multiple module paths; so my solution would not allow for multiple controller, model, class paths, etc. I agree with him. But my solution stands good for my initial aim though; so if you don’t plan to have multiple projects, you could use it till the community finds a different, community-wise global approach. Or you could suggest a solution?

Last, But Not The Least.. ReUse The Good Parts

After reading and observing the way DooPHP is going, I’m just reusing it’s MVC skeleton with it’s routing mechanism and then customizing it with the templating/DB layers/modules of my choice.

If you are wary about using a light-weight framework, then I suggest you move on with a full-stack one like Zend, Symfony or Solarphp. When it comes to framework, it all boils down to what you plan to achieve, then only decide which one best suit your objectives – of course you will need to get your hands dirty with a couple of the frameworks around to know where each stands and why it works for some and not for you.

What is your stand point? Have you tried DooPHP?

If You Appreciate What I Do Here On Seven PHP :: 7PHP, You Could Consider:

  1. Following me on Twitter | @7php
  2. LIKE-ing my FaceBook page
  3. Subscribe to my Email List - see top-right subscription box
  4. Help diffuse this interview to the PHP ecosystem - Share & Spread the word as far as you can ==> That would be a FREE way to thank me
  5. Use my DigitalOcean referral link if you plan to use it as your VPS (it starts at only $5/month btw) or if you can refer it to your friends, highly appreciated.
  6. Support via Paypal donate - my Paypal ID is w@7php.com

{I'm thankful to your response(s)!}

Valuable Feedback / Comment / Review From People Like You

  1. Vernon says:

    Thanks for sharing your thoughts on doophp moving protected folder outside your web root.
    Regards

Speak Your Mind

*