Okay, so I am creating an MVC framework in PHP and I want it to be pretty flexible. This is all fine - I'm working on this at the moment and things are going well (So I don't want to use Zend or another pre-existing framework, haha!), but I wanted to make both the framework and application quite dynamic. I'll try explain:
Here's a simplified directory structure:
- index.php (wants to use app1 or app2 depending on domain name)
- /app1 (wants to use framework 1.1)
- /config
- config.php
- /app2 (wants to use framework 1.2)
- /config
- config.php
- /framework_1.1
- /framework_1.2
A Bootstrap file /index.php receives all incoming requests. It will then load a certain application's config file from /app1/config/config.php or /app2/config/config.php, etc, depending on a certain condition, say.. the HTTP host:
// /index.php
switch ( $_SERVER[ 'HTTP_HOST' ] ) {
case 'localhost':
$app_root = ROOT . 'app1/';
break;
case 'site.com':
$app_root = ROOT . 'app2/';
break;
default:
$app_root = ROOT . 'application/';
break;
}
define('APP_ROOT', $app_root);
The bootstrap file then loads the application's config file:
// /index.php
include( APP_ROOT . 'config/config.php' );
A $config array will be returned from the application's config file, which will indicate where the framework files are located.
// /app2/config/config.php
$config['framework_root'] = '/framework_1.2/';
Bootstrap runs that framework.
// /index.php
include( $config['framework_root'] . 'config/bootstrap.php' );
Is this the best way to go about this?
The only problem with this, is that the /index.php file has to know about all possible applications, so the user will need to edit the switch statement in /index.php (or a /apps.php file that the /index.php includes, maybe?).
Also, the application's configuration file has to be loaded before loading the framework's files, which seems a bit weird to me...
Is there a simple way for making it so the request specifies application, and the application specifies which framework to use, or is the above way the simplest?
Sorry if this was confusing! Confused me a bit writing it ;)