<?php

if (!defined('APP_PATH_LIB')) define('APP_PATH_LIB', dirname( __FILE__ ));

class Lib {


	public static function loadClass($clsName) {
		return self::_loadClass($clsName, true);
	}


	public static function tryLoadClass($clsName) {
		return self::_loadClass($clsName, false);
	}


	/**
	 * load Class.
	 * 
	 * @example Core_Database_Mysql - check Core/Database/Mysql.php or Core_Database_Mysql.php file
	 */
	public static function _loadClass($clsName, $required = true) {
		$path = APP_PATH_LIB . '/' . implode('/', explode('_', $clsName)) . '.php';
		if (file_exists($path)) {
			require_once $path;
		} else {
			$path = APP_PATH_LIB . "/{$clsName}.php";
			if (file_exists($path)) {
				require_once $path;
			}
		}
		if (class_exists($clsName)) {
			return true;
		} else {
			if ($required) {
				die("Cant load class {$clsName}");
			}
			return false;
		}
	}

}
