No Description
unmaintained
experiment
php
database
native-app
php-gtk

OpenSQLManager.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * OpenSQLManager
  5. *
  6. * Free Database manager for Open Source Databases
  7. *
  8. * @package OpenSQLManager
  9. * @author Timothy J. Warren
  10. * @copyright Copyright (c) 2012
  11. * @link https://github.com/aviat4ion/OpenSQLManager
  12. * @license http://philsturgeon.co.uk/code/dbad-license
  13. */
  14. // --------------------------------------------------------------------------
  15. /**
  16. * Bootstrap file
  17. *
  18. * Initializes parent window and starts the GTK event loop
  19. */
  20. // --------------------------------------------------------------------------
  21. // Suppress errors that php-gtk puts out
  22. error_reporting(-1 & ~(E_STRICT));
  23. // Set the stupid timezone so PHP shuts up.
  24. date_default_timezone_set('GMT');
  25. // Don't set an arbitrary memory limit!
  26. ini_set('memory_limit', -1);
  27. // Set the current directory as the base for included files
  28. define('BASE_DIR', dirname(__FILE__).'/sys');
  29. define('SETTINGS_DIR', dirname(__FILE__));
  30. define('PROGRAM_NAME', 'OpenSQLManager');
  31. define('VERSION', '0.1.0pre');
  32. // --------------------------------------------------------------------------
  33. /**
  34. * Log fatal errors
  35. */
  36. function log_fatal()
  37. {
  38. // Catch the last error
  39. $error = error_get_last();
  40. // types of errors that are fatal
  41. $fatal = array(E_ERROR, E_PARSE, E_RECOVERABLE_ERROR);
  42. // Log error.
  43. if(in_array($error['type'], $fatal))
  44. {
  45. file_put_contents('errors.txt', print_r($error, TRUE), FILE_APPEND);
  46. }
  47. }
  48. register_shutdown_function('log_fatal');
  49. // --------------------------------------------------------------------------
  50. // Make sure php-gtk works
  51. if ( ! class_exists('gtk'))
  52. {
  53. trigger_error("PHP-gtk not found. Please load the php-gtk2 extension in your php.ini", E_USER_ERROR);
  54. die();
  55. }
  56. // Make sure pdo exists
  57. if( ! class_exists('pdo'))
  58. {
  59. trigger_error("PHP support for PDO is required.", E_USER_ERROR);
  60. die();
  61. }
  62. // --------------------------------------------------------------------------
  63. /**
  64. * Error handler to convert errors to exceptions
  65. *
  66. * @param int $errno
  67. * @param string $errstr
  68. * @param string $errfile
  69. * @param int $errline
  70. * @throws ErrorException
  71. */
  72. function exception_error_handler($errno, $errstr, $errfile, $errline)
  73. {
  74. throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
  75. }
  76. // Do this after the two compatibility checks for cleaner output
  77. // Note that this will throw exceptions on notices
  78. set_error_handler("exception_error_handler", E_ERROR | E_WARNING | E_NOTICE);
  79. // --------------------------------------------------------------------------
  80. if ( ! function_exists('do_include'))
  81. {
  82. /**
  83. * Bulk directory loading workaround for use
  84. * with array_map and glob
  85. *
  86. * @param string $path
  87. * @return void
  88. */
  89. function do_include($path)
  90. {
  91. require_once($path);
  92. }
  93. }
  94. // --------------------------------------------------------------------------
  95. /**
  96. * Autoloader for OpenSQLManager
  97. *
  98. * @param string $class
  99. */
  100. function osm_autoload($class)
  101. {
  102. $class = strtolower($class);
  103. $widget_path = BASE_DIR . "/widgets/{$class}.php";
  104. $window_path = BASE_DIR . "/windows/{$class}.php";
  105. if (is_file($widget_path))
  106. {
  107. require_once($widget_path);
  108. }
  109. elseif (is_file($window_path))
  110. {
  111. require_once($window_path);
  112. }
  113. }
  114. // --------------------------------------------------------------------------
  115. // Load everything so that we don't have to do requires later
  116. require_once(BASE_DIR . '/common/functions.php');
  117. spl_autoload_register('osm_autoload');
  118. // --------------------------------------------------------------------------
  119. // Auto-load db drivers
  120. require_once(BASE_DIR . "/db/autoload.php");
  121. // --------------------------------------------------------------------------
  122. // Create the main window
  123. new Main();
  124. // Start the GTK event loop
  125. GTK::main();
  126. // End of index.php