Well i think i may have come to a possible solution actually using a mix of ideas provided.
Code: Select all
require_once 'UPIConnectorDBWrapper.php';
$registry = new Settings();
$registry->dbsettings = array("db.database" => "chaf", "db.hostname" => "localhost", "db.username" => "chaf", "db.password" => "chaf");
$upi = new UPIConnectorDBWrapper(new UPIConnectorXml(),$registry);
print $upi->upi_login();
The set up looks a little more like this now, with more objects to help make things cleaner.
Code: Select all
abstract class store{} //simple registry abstract
interface IUPIConnector{}
class settings extends store{} //allows for specific functionality such as creating a singleton registry.
class VNdatabase{}
class UPIConnectorXml{}
class UPIConnectorDBWrapper extends VNDatabase implements IUPIConnector{}
I have (currently) removed the need for VNcore which originally looked like this where the settings were stored in an array and could be individually called if needed. Although the only thing is it is no longer secured by the fact the it was a protected function.
Code: Select all
class VNcore{
protected function getSettings($val = NULL){}
}
I am thinking however though i could in fact implement a singleton registry object to specifically contain the database information so that it can only be used by a single database connector.
Scratch that, i realised that if i in fact did make it a singleton registry, then any other class which makes use of the database settings object may run into problems where they cant access it all at once, causing the program to crash :S
And here is an example implementation of a UPIConnectorDBWrapper function which implements both a query and the use of the UPIConnectorXml class.
Code: Select all
public function upi_login() {
//example implementation of database
$q = $this->query("select * from mytable where id = '1'");
while($r = $this->fetch("assoc")){
$row[] = $r;
}
return $this->upiConnector->upi_login($row);
}
The only change that i had to make was in the constructor of UPIConnectorDBWrapper where x_mutatis_mutandis_x suggested i use, because i noticed that i was having to construct the IUPIConnector and pass that in instead of the the actual UPIConnectorXml which is where all the actual UPI functions would have been.
Code: Select all
public function __construct(IUPIConnector $upiConnector, $config = array()) {} //suggested
public function __construct(UPIConnectorXml $upiConnector, Settings $config) {} //actual
What is everyone's thoughts about this new set up? I think it has the potential to be a lot cleaner and manageable.