config/database.php
Code:
$database=array(
'host'=>'localhost',
'username'=>'pero',
);
$database=array(
'host'=>'localhost',
'username'=>'pero',
);
config/site.php
Code:
$site=array(
'title'=>'Moj sajt',
);
$site=array(
'title'=>'Moj sajt',
);
klasa config
Code:
<?php
class Config{
private static $instance;
private $config_name;
private $config=array();
private function __construct(){}
public static function __callStatic($config, $arg)
{
if(!isset(self::$instance))
{
self::$instance=new static;
}
if(!isset(self::$instance->config[$config]))
{
$config_path=__SITE_PATH.'config'.DS.$config.'.php';
if(!file_exists($config_path))
{
throw new Exception('Fajl konfiguracije '.$config_path.' ne postoji');
}
else
{
require_once $config_path;
self::$instance->config[$config]=$$config;
}
}
self::$instance->config_name=$config;
return self::$instance;
}
public function __get($index)
{
$config=$this->config[$this->config_name];
if(!isset($this->config[$this->config_name][$index]))
{
throw new Exception($this->config_name.'->'.$index.' nije definisan u konfiguraciji');
}
return $this->config[$this->config_name][$index];
}
}
<?php
class Config{
private static $instance;
private $config_name;
private $config=array();
private function __construct(){}
public static function __callStatic($config, $arg)
{
if(!isset(self::$instance))
{
self::$instance=new static;
}
if(!isset(self::$instance->config[$config]))
{
$config_path=__SITE_PATH.'config'.DS.$config.'.php';
if(!file_exists($config_path))
{
throw new Exception('Fajl konfiguracije '.$config_path.' ne postoji');
}
else
{
require_once $config_path;
self::$instance->config[$config]=$$config;
}
}
self::$instance->config_name=$config;
return self::$instance;
}
public function __get($index)
{
$config=$this->config[$this->config_name];
if(!isset($this->config[$this->config_name][$index]))
{
throw new Exception($this->config_name.'->'.$index.' nije definisan u konfiguraciji');
}
return $this->config[$this->config_name][$index];
}
}