Application
|---- User
|---- ACL
|---- MySQL
|---- DB2
|---- Oracle
|---- ORM
|---- Router
|---- Pages
|---- Models
L---- Controller
.... and while this has worked fine in the past I'm struggling with the concept of a persistent application that I can reference throughout the execution of the application (ie: a single page request). Previously I would simply pass any data that I needed through the function parameters as the need occasioned.
My new method involves the grouping of classes through categories - classes will exist which serve little to no purpose other than to provide a categorical namespace (not a literal PHP namespace) for pointers to children classes. So, the above tree would be reorganized thusly...
Application
|---- User
|-------- user funcs & properties
|---- Security
|---- Database
|-------- MySQL
|-------------- connect, ect. etc.
|-------- DB2
|-------------- connect, ect. etc.
|-------- Oracle
|-------------- connect, ect. etc.
|---- Page
|--------- Current
|--------- Request
The database example was the only one I really expanded out but hopefully you get the idea. So, for example, to connect to a MySQL database would be like this....
Code: Select all
<?php
$app = new Application();
$app->Database->MySQL->connect(CONNECTION_STRING);Example. Here's a look at the basic structure of the application.
Code: Select all
<?php
$app = new Application();
$app->MySQL->connect();
class Application
{
//Declare our Namespaces
public $User;
public $MySQL; //flattened the database class for the example
public function __construct()
{
$this->User = new User;
$this->User->username = "Jack";
$this->MySQL = new MySQL;
}
}
class User
{
public $username;
}
//separately.......
class MySQL
{
public function connect()
{
$username = $APPLICATION_REFERENCE->User->username;
mysql_connect(server, $username);
}
}