Lib.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. if (!defined('APP_PATH_LIB')) define('APP_PATH_LIB', dirname(__FILE__));
  3. class Lib {
  4. public static function loadClass($clsName) {
  5. return self::_loadClass($clsName, $required = true);
  6. }
  7. public static function tryLoadClass($clsName) {
  8. return self::_loadClass($clsName, $required = false);
  9. }
  10. /**
  11. * load Class.
  12. *
  13. * @example Core_Database_Mysql - check Core/Database/Mysql.php or Core_Database_Mysql.php file
  14. */
  15. public static function _loadClass($clsName, $required = true) {
  16. if (class_exists($clsName)) return true;
  17. $path = APP_PATH_LIB . '/' . implode('/', explode('_', $clsName)) . '.php';
  18. if (file_exists($path)) {
  19. require_once $path;
  20. } else {
  21. $path = APP_PATH_LIB . "/{$clsName}.php";
  22. if (file_exists($path)) {
  23. require_once $path;
  24. }
  25. }
  26. if (class_exists($clsName)) {
  27. return true;
  28. } else {
  29. if ($required) {
  30. die("Cant load class {$clsName}");
  31. }
  32. return false;
  33. }
  34. }
  35. public static function loadXslFunction($funcName) {
  36. return self::_loadXslFunction($funcName, $required = true);
  37. }
  38. public static function tryLoadXslFunction($funcName) {
  39. return self::_loadXslFunction($funcName, $required = false);
  40. }
  41. /**
  42. * load function.
  43. *
  44. * @example testFetchWfs -> SE/se-lib/xsl-functions/testFetchWfs.php // function testFetchWfs() {}
  45. * @example test_fetchWfs -> SE/se-lib/xsl-functions/test/fetchWfs.php // function test_fetchWfs() {}
  46. */
  47. public static function _loadXslFunction($funcName, $required = true) {
  48. DBG::log("_loadXslFunction({$funcName})...");
  49. if (function_exists($funcName)) return true;
  50. $path = APP_PATH_LIB . '/xsl-functions/' . implode('/', explode('_', $funcName)) . '.php';
  51. DBG::log("DBG _loadXslFunction: {$path}");
  52. if (file_exists($path)) {
  53. require_once $path;
  54. } else {
  55. $path = APP_PATH_LIB . "/xsl-functions/{$funcName}.php";
  56. DBG::log("DBG _loadXslFunction: {$path}");
  57. if (file_exists($path)) {
  58. require_once $path;
  59. }
  60. }
  61. if (function_exists($funcName)) {
  62. return true;
  63. } else {
  64. if ($required) {
  65. die("Cant load xsl function {$funcName}");
  66. }
  67. return false;
  68. }
  69. }
  70. }