파일에서 configs를 읽고 index.php에 설정된 기본 구성 변수를 가져 오는 (+ 그곳에서 설정) 모든 구성을 처리하는 클래스가 있습니다.다형성 - 모두 올바른지 확인
따라서 여기에서 다형성을 사용하기로 결정했습니다. 구성 클래스를 추상화하고 이것을 FILE 및 VARIABLE 클래스로 확장했습니다.
이 두 가지 책임을지는 기본 클래스가 100 줄 길이라면 좋은 행동입니까?
여기에 저의 의견을 말하지 마십시오. 프로젝트가 이미 완료되었을 때 유연한 해결책이 아니라는 사실을 알고 싶지 않습니다.
이것은 리팩토링, 테스트 및 몇 가지 기능을 추가하지 않은 코드이지만 개념은 명확해야합니다.
class Config {
private $file;
public static $configs = array();
/**
* Initializes basic website configurations such as base URL, or the name
* of the index file.
*
* These values can be accessed through this class
*/
public static function init($configs = array())
{
foreach($configs as $key => $value)
{
self::$configs[$key] = $value;
}
}
/**
* Returns the configuration variable which is set in the index file
*
* @param string $attribute
* @return multitype:
*/
public function __get($attribute)
{
return ($this->configs[$attribute]) ? $this->configs[$attribute] : -1;
}
/**
* Setting path to the config file.
*
* @param string $module
*/
private function __construct($module)
{
// Path to the config file
$path = APATH . 'config' . DIRECTORY_SEPARATOR . $module . '.php';
// Set the config file to the attribute here
$this->file = include $path;
}
/**
* Return the object.
*
*/
public static function factory($module)
{
return new Config($module);
}
/**
* Loads configurations from the given file.
*
*/
public function load($property)
{
// Return requested value
return $array[$property];
}
}
일부 코드는 게시 하시겠습니까? – mauris
http://codereview.stackexchange.com이 더 적절한 사이트 일 수 있습니다. –
누가 가장 좋아하는 질문입니까? xD – user1615069