<?
class Serval{
  public static $obj = array();
  
  public static function build($id,$__construct = null,$name=null){
      $arr = explode(':',$id);
      $class = reset($arr);
			if(!$class) return false; 
			self::$obj[$id] = $__construct ?  new $class($__construct) : new $class();
      return self::$obj[$id];
  }

  public static function call($id,$__construct = null, $name=null){
    if(!isset(self::$obj[$id])){
      return self::build($id,$__construct,$name);
    }else{ 
      return self::$obj[$id];
    }
  }
  
  public static function kill($id){
    if(isset(self::$obj[$id])){
      unset(self::$obj[$id]);
      return true;
    }
    return false;
  }
  
  public static function _autoload($a){
	global $config;
		$path = "lib/Class.{$a}.php";
		if( file_exists($config['root'].'/'.$path) ){
			include_once($config['root'].'/'.$path);
		}else{
			die("Error Serval::autoload {$path}");
		} 
  }
  
}
?>