All pastes #237441 Raw Edit

iowa

public php v1 · immutable
·published 2006-11-04 15:26 UTC
rendered paste body
<?phpdefine('DS', DIRECTORY_SEPARATOR);set_exception_handler('excp');define('E_CHMOD', 1);define('E_WRITE', 2);define('E_READ', 3);define('E_404', 4);function excp($e){	main::error($e->getmessage(), $e->getcode());}class main {		const ext_classes = '.class.php';	const ext = '.php';	const dir_classes = 'classes';	const show_errors = 1;		static function add($name, $params = array()){		$path = self::dir_classes.DS.$name.self::ext_classes;				if(!file_exists($path)) throw new Exception($path, E_404);		if(!is_readable($path)) throw new Exception($path, E_READ);				require_once($path);		return new $name($params);			}	static function ct(){		return mktime();	}	static function error($msg, $type){		switch($type){			case E_404: $message = 'ei leidnud faili: '; break;			default: $message = 'error: '; break;		}				if(self::show_errors) print self::ct().' : '.$message.$msg;		else print 'error: viga on loogitud ning parandatakse loodetavasti lähiajal.';		exit(1);	}	static function strtofile($filepath, $str, $permission = 'a+'){		@$fh = fopen($filepath, $permission);		if(!$fh) throw new exception($filepath, E_WRITE);		fwrite($fh, $str);		fclose($fh);	}	static function chmod($file, $permission){		if(!chmod($file, $permission)) throw new exception($file, E_CHMOD);	}}main::strtofile('willywonka.php','pee');?>