2012-05-07 15:01:39 -04:00
|
|
|
#!/usr/bin/env php
|
2012-01-26 16:09:05 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* OpenSQLManager
|
|
|
|
*
|
|
|
|
* Free Database manager for Open Source Databases
|
|
|
|
*
|
2012-04-20 13:30:27 -04:00
|
|
|
* @package OpenSQLManager
|
2012-01-26 16:09:05 -05:00
|
|
|
* @author Timothy J. Warren
|
|
|
|
* @copyright Copyright (c) 2012
|
|
|
|
* @link https://github.com/aviat4ion/OpenSQLManager
|
2012-03-28 11:23:08 -04:00
|
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
2012-01-26 16:09:05 -05:00
|
|
|
*/
|
2012-01-27 16:57:59 -05:00
|
|
|
|
2012-02-01 16:36:55 -05:00
|
|
|
// --------------------------------------------------------------------------
|
2012-01-27 16:57:59 -05:00
|
|
|
|
2012-02-01 16:36:55 -05:00
|
|
|
/**
|
|
|
|
* Bootstrap file
|
|
|
|
*
|
2012-05-29 06:21:30 -04:00
|
|
|
* Initializes parent window and starts the wx event loop
|
2012-02-01 16:36:55 -05:00
|
|
|
*/
|
2012-01-27 16:57:59 -05:00
|
|
|
|
2012-05-29 06:21:30 -04:00
|
|
|
namespace OpenSQLManager;
|
2012-01-27 16:57:59 -05:00
|
|
|
|
2012-05-29 06:21:30 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-05-25 20:30:06 -04:00
|
|
|
error_reporting(-1);
|
2012-01-31 16:41:30 -05:00
|
|
|
|
2012-02-01 16:36:55 -05:00
|
|
|
// Set the stupid timezone so PHP shuts up.
|
|
|
|
date_default_timezone_set('GMT');
|
|
|
|
|
2012-04-10 09:38:57 -04:00
|
|
|
// Don't set an arbitrary memory limit!
|
2012-04-04 10:47:14 -04:00
|
|
|
ini_set('memory_limit', -1);
|
|
|
|
|
2012-02-01 16:36:55 -05:00
|
|
|
// Set the current directory as the base for included files
|
2012-02-29 16:14:21 -05:00
|
|
|
define('BASE_DIR', dirname(__FILE__).'/sys');
|
|
|
|
define('SETTINGS_DIR', dirname(__FILE__));
|
2012-04-02 13:04:53 -04:00
|
|
|
define('PROGRAM_NAME', 'OpenSQLManager');
|
2012-04-02 16:56:55 -04:00
|
|
|
define('VERSION', '0.1.0pre');
|
2012-02-01 16:36:55 -05:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-01-31 16:41:30 -05:00
|
|
|
/**
|
|
|
|
* Log fatal errors
|
|
|
|
*/
|
|
|
|
function log_fatal()
|
|
|
|
{
|
|
|
|
// Catch the last error
|
2012-02-01 14:45:38 -05:00
|
|
|
$error = error_get_last();
|
2012-01-31 16:41:30 -05:00
|
|
|
|
2012-02-01 14:45:38 -05:00
|
|
|
// types of errors that are fatal
|
|
|
|
$fatal = array(E_ERROR, E_PARSE, E_RECOVERABLE_ERROR);
|
2012-01-31 16:41:30 -05:00
|
|
|
|
2012-02-02 11:27:42 -05:00
|
|
|
// Log error.
|
2012-05-29 14:29:20 -04:00
|
|
|
if(in_array($error['type'], $fatal))
|
|
|
|
{
|
2012-02-01 14:45:38 -05:00
|
|
|
file_put_contents('errors.txt', print_r($error, TRUE), FILE_APPEND);
|
2012-05-29 14:29:20 -04:00
|
|
|
}
|
2012-01-31 16:41:30 -05:00
|
|
|
}
|
|
|
|
|
2012-05-29 06:21:30 -04:00
|
|
|
register_shutdown_function('OpenSQLManager\log_fatal');
|
2012-01-30 18:44:27 -05:00
|
|
|
|
2012-02-01 16:36:55 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-01-31 17:52:46 -05:00
|
|
|
// Make sure php-gtk works
|
2012-05-25 20:30:06 -04:00
|
|
|
if ( ! class_exists('wxApp'))
|
2012-01-26 16:09:05 -05:00
|
|
|
{
|
2012-05-25 20:30:06 -04:00
|
|
|
trigger_error("wxPHP not found. Please load the wxPHP extension in your php.ini", E_USER_ERROR);
|
2012-02-01 16:36:55 -05:00
|
|
|
die();
|
2012-01-26 16:09:05 -05:00
|
|
|
}
|
|
|
|
|
2012-02-01 16:36:55 -05:00
|
|
|
// Make sure pdo exists
|
|
|
|
if( ! class_exists('pdo'))
|
|
|
|
{
|
|
|
|
trigger_error("PHP support for PDO is required.", E_USER_ERROR);
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
2012-01-27 21:19:39 -05:00
|
|
|
|
2012-04-11 14:57:38 -04:00
|
|
|
/**
|
|
|
|
* Error handler to convert errors to exceptions
|
|
|
|
*
|
|
|
|
* @param int $errno
|
|
|
|
* @param string $errstr
|
|
|
|
* @param string $errfile
|
|
|
|
* @param int $errline
|
|
|
|
* @throws ErrorException
|
|
|
|
*/
|
2012-04-10 10:47:37 -04:00
|
|
|
function exception_error_handler($errno, $errstr, $errfile, $errline)
|
2012-04-10 09:38:57 -04:00
|
|
|
{
|
2012-05-29 06:21:30 -04:00
|
|
|
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
|
2012-04-10 09:38:57 -04:00
|
|
|
}
|
2012-04-11 14:57:38 -04:00
|
|
|
|
|
|
|
// Do this after the two compatibility checks for cleaner output
|
|
|
|
// Note that this will throw exceptions on notices
|
2012-05-29 06:21:30 -04:00
|
|
|
set_error_handler("OpenSQLManager\exception_error_handler", E_ERROR | E_WARNING | E_NOTICE);
|
2012-04-10 09:38:57 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-04-12 14:06:00 -04:00
|
|
|
if ( ! function_exists('do_include'))
|
2012-01-27 12:58:03 -05:00
|
|
|
{
|
2012-04-19 12:29:47 -04:00
|
|
|
/**
|
|
|
|
* Bulk directory loading workaround for use
|
|
|
|
* with array_map and glob
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-04-12 14:06:00 -04:00
|
|
|
function do_include($path)
|
|
|
|
{
|
|
|
|
require_once($path);
|
|
|
|
}
|
2012-01-27 12:58:03 -05:00
|
|
|
}
|
|
|
|
|
2012-04-12 14:06:00 -04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-05-21 16:18:24 -04:00
|
|
|
/**
|
|
|
|
* Autoloader for OpenSQLManager
|
|
|
|
*
|
|
|
|
* @param string $class
|
|
|
|
*/
|
|
|
|
function osm_autoload($class)
|
2012-01-31 11:39:30 -05:00
|
|
|
{
|
2012-05-29 06:21:30 -04:00
|
|
|
$class_spaces = explode('\\', $class);
|
|
|
|
$class = strtolower(end($class_spaces));
|
2012-05-21 16:18:24 -04:00
|
|
|
$widget_path = BASE_DIR . "/widgets/{$class}.php";
|
|
|
|
$window_path = BASE_DIR . "/windows/{$class}.php";
|
|
|
|
|
|
|
|
if (is_file($widget_path))
|
|
|
|
{
|
|
|
|
require_once($widget_path);
|
|
|
|
}
|
|
|
|
elseif (is_file($window_path))
|
|
|
|
{
|
|
|
|
require_once($window_path);
|
|
|
|
}
|
2012-01-31 11:39:30 -05:00
|
|
|
}
|
2012-01-26 16:09:05 -05:00
|
|
|
|
2012-02-01 16:36:55 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-05-21 16:18:24 -04:00
|
|
|
// Load everything so that we don't have to do requires later
|
|
|
|
require_once(BASE_DIR . '/common/functions.php');
|
2012-05-29 06:21:30 -04:00
|
|
|
spl_autoload_register('OpenSQLManager\osm_autoload');
|
2012-05-21 16:18:24 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-04-12 14:06:00 -04:00
|
|
|
// Auto-load db drivers
|
|
|
|
require_once(BASE_DIR . "/db/autoload.php");
|
2012-02-01 16:36:55 -05:00
|
|
|
|
2012-03-27 15:47:56 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-05-29 06:21:30 -04:00
|
|
|
// ! App Bootstrap class
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-05-29 14:29:20 -04:00
|
|
|
// The main Window object
|
|
|
|
$main = new Main();
|
|
|
|
|
2012-05-29 06:21:30 -04:00
|
|
|
/**
|
|
|
|
* Class for the app itself
|
|
|
|
*
|
|
|
|
* @package OpenSQLManager
|
|
|
|
*/
|
|
|
|
class OpenSQLManager extends \wxApp {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the app
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function OnInit()
|
|
|
|
{
|
2012-05-29 14:29:20 -04:00
|
|
|
global $main;
|
2012-05-29 06:21:30 -04:00
|
|
|
$main->show();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return exit code
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function OnExit()
|
|
|
|
{
|
2012-05-29 14:29:20 -04:00
|
|
|
\wxExit();
|
2012-05-29 06:21:30 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2012-03-27 15:47:56 -04:00
|
|
|
|
2012-05-29 14:29:20 -04:00
|
|
|
// Create the app instance
|
2012-05-29 06:21:30 -04:00
|
|
|
$app = new OpenSQLManager();
|
2012-01-26 16:09:05 -05:00
|
|
|
|
2012-05-29 14:29:20 -04:00
|
|
|
// Create platform information object
|
|
|
|
$platform = new \wxPlatformInfo();
|
|
|
|
|
|
|
|
// Pass fatal exceptions to wxAPP
|
|
|
|
\wxHandleFatalExceptions(TRUE);
|
|
|
|
|
2012-05-25 20:30:06 -04:00
|
|
|
// Start the wx event loop
|
2012-05-29 06:21:30 -04:00
|
|
|
\wxApp::SetInstance($app);
|
|
|
|
\wxEntry();
|
2012-01-27 16:57:59 -05:00
|
|
|
|
2012-05-29 06:21:30 -04:00
|
|
|
// End of OpenSQLManager.php
|