Fix dl on windows

This commit is contained in:
Timothy Warren 2012-12-03 14:42:57 -05:00
parent abb126c400
commit 887dc7ff8d
1 changed files with 216 additions and 209 deletions

View File

@ -1,210 +1,217 @@
<?php <?php
/** /**
* OpenSQLManager * OpenSQLManager
* *
* Free Database manager for Open Source Databases * Free Database manager for Open Source Databases
* *
* @package OpenSQLManager * @package OpenSQLManager
* @author Timothy J. Warren * @author Timothy J. Warren
* @copyright Copyright (c) 2012 * @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager * @link https://github.com/aviat4ion/OpenSQLManager
* @license https://timshomepage.net/dbaj.txt * @license https://timshomepage.net/dbaj.txt
*/ */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Bootstrap file * Bootstrap file
* *
* Initializes parent window and starts the wx event loop * Initializes parent window and starts the wx event loop
*/ */
namespace OpenSQLManager; namespace OpenSQLManager;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
error_reporting(-1); error_reporting(-1);
// Set the stupid timezone so PHP shuts up. // Set the stupid timezone so PHP shuts up.
date_default_timezone_set('GMT'); date_default_timezone_set('GMT');
// Don't set an arbitrary memory limit! // Don't set an arbitrary memory limit!
ini_set('memory_limit', -1); ini_set('memory_limit', -1);
// Set the current directory as the base for included files // Set the current directory as the base for included files
define('OSM_BASE_DIR', __DIR__.'/sys'); define('OSM_BASE_DIR', __DIR__.'/sys');
define('OSM_RESOURCE_DIR', realpath(__DIR__.'/../Resources')); define('OSM_RESOURCE_DIR', realpath(__DIR__.'/../Resources'));
define('OSM_SETTINGS_DIR', __DIR__); define('OSM_SETTINGS_DIR', __DIR__);
define('OSM_PROGRAM_NAME', 'OpenSQLManager'); define('OSM_PROGRAM_NAME', 'OpenSQLManager');
define('OSM_VERSION', '0.2.0pre'); define('OSM_VERSION', '0.2.0pre');
echo OSM_RESOURCE_DIR . "\n"; echo OSM_RESOURCE_DIR . "\n";
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Log fatal errors * Log fatal errors
*/ */
function log_fatal() function log_fatal()
{ {
// Catch the last error // Catch the last error
$error = error_get_last(); $error = error_get_last();
// types of errors that are fatal // types of errors that are fatal
$fatal = [E_ERROR, E_PARSE, E_RECOVERABLE_ERROR]; $fatal = [E_ERROR, E_PARSE, E_RECOVERABLE_ERROR];
// Log error. // Log error.
if(in_array($error['type'], $fatal)) //if(in_array($error['type'], $fatal))
{ {
file_put_contents('errors.txt', print_r($error, TRUE), FILE_APPEND); file_put_contents('errors.txt', print_r($error, TRUE), FILE_APPEND);
} }
} }
register_shutdown_function('OpenSQLManager\log_fatal'); register_shutdown_function('OpenSQLManager\log_fatal');
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Make sure wxphp works // Make sure wxphp works
if ( ! class_exists('wxApp')) if ( ! class_exists('wxApp'))
{ {
// Try to load wxphp if possible // Try to load wxphp if possible
if (function_exists('dl') && in_array(php_sapi_name(), ['cli', 'embed'])) // Windows is special
{ if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
$name = 'wxwidgets.'.PHP_SHLIB_SUFFIX; {
dl($name); $name = 'php_wxwidgets.dll';
} }
else else
{ {
trigger_error("wxPHP not found. Please load the wxPHP extension in your php.ini", E_USER_ERROR); $name .= 'wxwidgets.'.PHP_SHLIB_SUFFIX;
die(); }
}
} $res = dl($name);
// Make sure pdo exists if ( ! $res)
if( ! class_exists('pdo')) {
{ trigger_error("wxPHP not found. Please load the wxPHP extension in your php.ini", E_USER_ERROR);
trigger_error("PHP support for PDO is required.", E_USER_ERROR); die();
die(); }
} }
// -------------------------------------------------------------------------- // Make sure pdo exists
if( ! class_exists('pdo'))
/** {
* Error handler to convert errors to exceptions trigger_error("PHP support for PDO is required.", E_USER_ERROR);
* die();
* @param int $errno }
* @param string $errstr
* @param string $errfile // --------------------------------------------------------------------------
* @param int $errline
* @throws ErrorException /**
*/ * Error handler to convert errors to exceptions
function exception_error_handler($errno, $errstr, $errfile, $errline) *
{ * @param int $errno
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); * @param string $errstr
} * @param string $errfile
* @param int $errline
// Do this after the two compatibility checks for cleaner output * @throws ErrorException
// Note that this will throw exceptions on notices */
set_error_handler('OpenSQLManager\exception_error_handler', -1); function exception_error_handler($errno, $errstr, $errfile, $errline)
{
// -------------------------------------------------------------------------- throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
}
if ( ! function_exists('do_include'))
{ // Do this after the two compatibility checks for cleaner output
/** // Note that this will throw exceptions on notices
* Bulk directory loading workaround for use set_error_handler('OpenSQLManager\exception_error_handler', -1);
* with array_map and glob
* // --------------------------------------------------------------------------
* @param string $path
* @return void if ( ! function_exists('do_include'))
*/ {
function do_include($path) /**
{ * Bulk directory loading workaround for use
require_once($path); * with array_map and glob
} *
} * @param string $path
* @return void
// -------------------------------------------------------------------------- */
function do_include($path)
/** {
* Autoloader for OpenSQLManager require_once($path);
* }
* @param string $class }
*/
function osm_autoload($class) // --------------------------------------------------------------------------
{
$class_spaces = explode('\\', $class); /**
$class = strtolower(end($class_spaces)); * Autoloader for OpenSQLManager
$widget_path = OSM_BASE_DIR . "/widgets/{$class}.php"; *
$window_path = OSM_BASE_DIR . "/windows/{$class}.php"; * @param string $class
*/
if (is_file($widget_path)) function osm_autoload($class)
{ {
require_once($widget_path); $class_spaces = explode('\\', $class);
} $class = strtolower(end($class_spaces));
elseif (is_file($window_path)) $widget_path = OSM_BASE_DIR . "/widgets/{$class}.php";
{ $window_path = OSM_BASE_DIR . "/windows/{$class}.php";
require_once($window_path);
} if (is_file($widget_path))
} {
require_once($widget_path);
// -------------------------------------------------------------------------- }
elseif (is_file($window_path))
// Load all the common classes, and register the autoloader {
array_map('OpenSQLManager\do_include', glob(OSM_BASE_DIR.'/common/*.php')); require_once($window_path);
spl_autoload_register('OpenSQLManager\osm_autoload'); }
}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// Auto-load db drivers
require_once(OSM_BASE_DIR . "/db/autoload.php"); // Load all the common classes, and register the autoloader
array_map('OpenSQLManager\do_include', glob(OSM_BASE_DIR.'/common/*.php'));
// -------------------------------------------------------------------------- spl_autoload_register('OpenSQLManager\osm_autoload');
// ! App Bootstrap class
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** // Auto-load db drivers
* Class for the app itself require_once(OSM_BASE_DIR . "/db/autoload.php");
*
* @package OpenSQLManager // --------------------------------------------------------------------------
*/ // ! App Bootstrap class
class OpenSQLManager extends \wxApp { // --------------------------------------------------------------------------
/** /**
* Initialize the app * Class for the app itself
* *
* @return int * @package OpenSQLManager
*/ */
public function OnInit() class OpenSQLManager extends \wxApp {
{
// The main Window object /**
$main = new Main(); * Initialize the app
$main->show(); *
* @return int
return 0; */
} public function OnInit()
{
/** // The main Window object
* Return exit code $main = new Main();
* $main->show();
* @return int
*/ return 0;
public function OnExit() }
{
\wxExit(); /**
return 0; * Return exit code
} *
} * @return int
*/
// Create the app instance public function OnExit()
$app = new OpenSQLManager(); {
\wxExit();
// Create platform information object return 0;
$platform = new \wxPlatformInfo(); }
}
// Define the platform for later use
define('PLATFORM', $platform->GetOperatingSystemId()); // Create the app instance
$app = new OpenSQLManager();
// Start the wx event loop
\wxApp::SetInstance($app); // Create platform information object
\wxEntry(); $platform = new \wxPlatformInfo();
// Define the platform for later use
define('PLATFORM', $platform->GetOperatingSystemId());
// Start the wx event loop
\wxApp::SetInstance($app);
\wxEntry();
// End of OpenSQLManager.php // End of OpenSQLManager.php