I see nothing that should prevent you from doing what you have outlined.
The closest thing I have worked with:
I once wrote a set of classes which works with data having a tree relationship (a node must have a parent unless it's a root node). The actual tree data could be stored either on the file system (where the directory system already implements a tree relationship) or in a database.
The classes were:
Low-level (storage concerned) classes:
- SQLtree
- FStree
Higher level (data definition):
- TreeNode
Now, since PHP doesn't have multiple inheritance, I did it this way:
The low-level tree classes contained all methods needed for storage. Also, the tree classes contained the two following methods:
getRootNode()
getNodeById(int id)
So if you wanted to work with the database implementation, you'd create a node this way:
$t = new SQLtree('nameOfTree'); // returns an object
// of the TreeNode class
$rn = $t->getRootNode(); // returns an object
// of the TreeNode class
$n = $rn -> createChild(); // returns an object
// of the TreeNode class
$n->setAttribute('surname','Andersen','string');
$n->saveAttributes();
If I had wanted the file-system based implementation of the tree, I'd do it like this:
$t = new FStree('nameOfTree');
$rn = $t->getRoodNode();
$n = rn->createChild();
...
I don't know if this helps.