dakata__92
Super Moderator
Колеги, правилно ли съм драснал според вас тези методи? Трябва ли да има отделно сетер и гетер или и това което съм написал е правилно от гледна точка на ООП.
PHP:
public function getConnection($class = "\system\database\PDO",$dbname=null){
if(in_array("system\interfaces\iDatabase",class_implements($class))){
if(empty($this->dbConnection)){
$cnf = $this->getConfiguration()->load('database/connection');
if(is_null($dbname)){
return $this->dbConnection = new $class($cnf['host'],$cnf['user'],$cnf['pass'],$cnf['name']);
}
return $this->dbConnection = new $class($cnf['host'],$cnf['user'],$cnf['pass'],$dbname);
}
return $this->dbConnection;
}else{
throw new \Exception("Class not implements the interface [system\interfaces\iDatabase].",500);
}
}
public function getRouter($router = "\system\router\Router"){
if(in_array("system\interfaces\iRouter",class_implements($router))){
return new $router();
}else{
throw new \Exception("Class not implements the interface [system\interfaces\iRouter].",500);
}
}