dakata__92
Super Moderator
Създадох си един клас който да ми обработва дефаутовите настройки на работната рамка.
Класът:
В главният апликейшън клас правя така в конструктора му и е сингълтон:
И разпространявам настройките из файловете където е нужно така:
Въпроса ми е това добре ли е ? Чедух се дали да не дефинирам като константа този тези масиви define() и да си ги викам като такива? Дайте идея да го подобря.
Класът:
PHP:
<?php
namespace system\core;
class MDC{
private static $instance = null;
private $configFolder = null;
private function __construct() {
}
public function setConfigFolder($configFolder) {
if(!$configFolder){
throw new \Exception('Empty config folder path.',500);
}
$_configFolder = realpath($configFolder);
if($_configFolder && is_dir($_configFolder) && is_readable($_configFolder)){
$this->configFolder = $_configFolder . DIRECTORY_SEPARATOR;
return $this;
}else{
throw new \Exception('Config directory read error:' . $configFolder);
}
}
public function load($filePathName,$extension='.php'){
$path = $this->configFolder.$filePathName.$extension;
$_path = realpath($path);
if(file_exists($_path) && is_readable($_path)){
return include $_path;
}else{
throw new \Exception("No such file path: [".$path."] in this [".$this->configFolder.'] directory!', 500);
}
}
public function getConfigFolder() {
return $this->configFolder;
}
public static function getInstance(){
if(self::$instance == null){
self::$instance = new self();
}
return self::$instance;
}
}
В главният апликейшън клас правя така в конструктора му и е сингълтон:
PHP:
private function __construct(){
$this->MDC = \system\core\MDC::getInstance();
if($this->MDC->getConfigFolder() == null){
$this->MDC->setConfigFolder($this->configFolder);
}
}
public function MDC() {
return $this->MDC;
}
И разпространявам настройките из файловете където е нужно така:
PHP:
// $this->opt = $this->options('core/'.$this->className);
private function options($path){
return \system\core\SAL::getInstance()->MDC()->load($path);
}
Въпроса ми е това добре ли е ? Чедух се дали да не дефинирам като константа този тези масиви define() и да си ги викам като такива? Дайте идея да го подобря.