am writing a small set of framework structures for PHP (not be confused with a MVC style framework) and I would to like to validate my approach because it seems very "clumsy":
All requests are piped to a bootstraper through redirect directive (apache htaccess).
All necessary files are required by the bootstrapper.
Then user classes are called based on routes (this works fine, not included here)
Each user module extends core module, that in turn instantiates support classes like DB and CACHE, thus inherits the instances and I don't have to care about opening/managing connections or if I instantiate other classes within those classes - I don't have to pass my db/cache as arguments. Also, if I have a large request with plenty of user class methods calls within the same request - I think it would only use one instance of the core.module - which should be a good thing. Right? Right?
However, the config passing seems to be iffy: I hate GLOBALS with passion - BUT I cant make a static config class because I can not put the array there (no static arrays in PHP). Also, this breaks all the IDE intellisenses and the devs are mad at me :(
Does the whole approach make sense? Should I go RTM more?
Thank you for your honest opinions, the pseudo-code is attached below.
//my_config_prod.php
<?php
$CONFIG = array('db' => array(..multi-level array here..), 'cache' => array(...));
?>
//bootstraper.php
<?php
require '../config/my_config_prod.php';
require '../core/core.mysql.php';
require '../core/core.cache.php';
require '../core/core.module.php';
require '../class/class.user.php';
//initialize things:
$GLOBALS['DB'] = new CoreMysql($CONFIG['db']);
$GLOBALS['CACHE'] = new CoreCache($CONFIG['cache']);
//run, this is simplified - route handler is installed here that will
//call appropriate module based on the incoming request
$user = new User();
$info = $user->load_user(1);
?>
//core.module.php
<?php
public function __construct () {
global $CACHE;
$this->cache = $CACHE;
global $DB;
$this->db = $DB;
}
?>
//class.user.php
<?php
class User extends CoreModule{
public function __construct() {
parent::__construct();
}
public function load_user($id) {
return $this->db->get_user($id)
}
}
?>