From: Roland Haeder Date: Tue, 20 Jan 2015 21:45:58 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=75d22b262f62dd88e577ade6da3d6be9d34b9930;p=core.git Continued: - Added new field 'regularExpression' which can be used for validating data - Added stub application for unit tests on the framework Signed-off-by: Roland Häder --- diff --git a/application/.htaccess b/application/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/application/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/tests/.htaccess b/application/tests/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/application/tests/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/tests/class_ApplicationHelper.php b/application/tests/class_ApplicationHelper.php new file mode 100644 index 00000000..f05d1d9f --- /dev/null +++ b/application/tests/class_ApplicationHelper.php @@ -0,0 +1,234 @@ + + * @version 0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication, Registerable { + /** + * The version number of this application + */ + private $appVersion = ''; + + /** + * The human-readable name for this application + */ + private $appName = ''; + + /** + * The short uni*-like name for this application + */ + private $shortName = ''; + + /** + * An instance of this class + */ + private static $selfInstance = NULL; + + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Getter for an instance of this class + * + * @return $selfInstance An instance of this class + */ + public static final function getSelfInstance () { + // Is the instance there? + if (is_null(self::$selfInstance)) { + self::$selfInstance = new ApplicationHelper(); + } // END - if + + // Return the instance + return self::$selfInstance; + } + + /** + * Getter for the version number + * + * @return $appVersion The application's version number + */ + public final function getAppVersion () { + return $this->appVersion; + } + /** + * Setter for the version number + * + * @param $appVersion The application's version number + * @return void + */ + public final function setAppVersion ($appVersion) { + // Cast and set it + $this->appVersion = (string) $appVersion; + } + + /** + * Getter for human-readable name + * + * @return $appName The application's human-readable name + */ + public final function getAppName () { + return $this->appName; + } + + /** + * Setter for human-readable name + * + * @param $appName The application's human-readable name + * @return void + */ + public final function setAppName ($appName) { + // Cast and set it + $this->appName = (string) $appName;; + } + + /** + * Getter for short uni*-like name + * + * @return $shortName The application's short uni*-like name + */ + public final function getAppShortName () { + return $this->shortName; + } + + /** + * Setter for short uni*-like name + * + * @param $shortName The application's short uni*-like name + * @return void + */ + public final function setAppShortName ($shortName) { + // Cast and set it + $this->shortName = (string) $shortName; + } + + /** + * Launches the test suite + * + * @return void + */ + public final function entryPoint () { + // Set this application in registry + Registry::getRegistry()->addInstance('app', $this); + + // Default response is console + $response = $this->getResponseTypeFromSystem(); + $responseType = $this->getResponseTypeFromSystem(); + + // Create a new request object + $requestInstance = ObjectFactory::createObjectByName($this->convertToClassName($response) . 'Request'); + + // Remember request instance here + $this->setRequestInstance($requestInstance); + + // Do we have another response? + if ($requestInstance->isRequestElementSet('request')) { + // Then use it + $response = strtolower($requestInstance->getRequestElement('request')); + $responseType = $response; + } // END - if + + // ... and a new response object + $responseClass = sprintf('%sResponse', $this->convertToClassName($response)); + $responseInstance = ObjectFactory::createObjectByName($responseClass, array($this)); + + // Remember response instance here + $this->setResponseInstance($responseInstance); + + // Get the parameter from the request + $commandName = $requestInstance->getRequestElement('command'); + + // If it is null then get default command + if (is_null($commandName)) { + // Get default command + $commandName = $responseInstance->getDefaultCommand(); + + // Set it in request + $requestInstance->setRequestElement('command', $commandName); + } // END - if + + // Get a controller resolver + $resolverClass = $this->convertToClassName($this->getAppShortName() . '_' . $responseType . '_controller_resolver'); + $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this)); + + // Get a controller instance as well + $this->setControllerInstance($resolverInstance->resolveController()); + + // Launch the test suite here + $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance); + + // -------------------------- Shutdown phase -------------------------- + // Shutting down the hub by saying "good bye" to all connected peers + // and other hubs, flushing all queues and caches. + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown in progress, main loop exited.'); + $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance); + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)'); + } + + /** + * Handle the indexed array of fatal messages and puts them out in an + * acceptable fasion + * + * @param $messageList An array of fatal messages + * @return void + */ + public function handleFatalMessages (array $messageList) { + // Walk through all messages + foreach ($messageList as $message) { + exit(__METHOD__ . ':MSG:' . $message); + } // END - foreach + } + + /** + * Builds the master template's name + * + * @return $masterTemplateName Name of the master template + */ + public function buildMasterTemplateName () { + return 'node_main'; + } +} + +// [EOF] +?> diff --git a/application/tests/config.php b/application/tests/config.php new file mode 100644 index 00000000..477c7e19 --- /dev/null +++ b/application/tests/config.php @@ -0,0 +1,31 @@ + + * @version 0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// Some hub-specific configuration like port hostname where we will listen, etc. +$cfg = FrameworkConfiguration::getSelfInstance(); + +// CFG: DEFAULT-CONSOLE-COMMAND +$cfg->setConfigEntry('default_console_command', 'tests'); + +// [EOF] +?> diff --git a/application/tests/data.php b/application/tests/data.php new file mode 100644 index 00000000..f8aa236b --- /dev/null +++ b/application/tests/data.php @@ -0,0 +1,43 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// Get config instance +$cfg = FrameworkConfiguration::getSelfInstance(); + +// Get an instance of the helper +$app = call_user_func_array( + array($cfg->getConfigEntry('app_helper_class'), 'getSelfInstance'), + array() +); + +// Set application name and version +$app->setAppName('Unit tests and more'); +$app->setAppVersion('0.0.0'); +$app->setAppShortName('tests'); + +// [EOF] +?> diff --git a/application/tests/debug.php b/application/tests/debug.php new file mode 100644 index 00000000..a27fdb47 --- /dev/null +++ b/application/tests/debug.php @@ -0,0 +1,28 @@ + + * @version 0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// Set error reporting +error_reporting(E_ALL | E_STRICT); + +// [EOF] +?> diff --git a/application/tests/exceptions.php b/application/tests/exceptions.php new file mode 100644 index 00000000..e483dafd --- /dev/null +++ b/application/tests/exceptions.php @@ -0,0 +1,143 @@ + + * @version 0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// The node's own exception handler +function tests_exception_handler ($exceptionInstance) { + // Is it an object and a valid instance? + if ((is_object($exceptionInstance)) && ($exceptionInstance instanceof FrameworkException)) { + // Init variable + $backTrace = ''; + + // Get all call levels from backtrace + foreach ($exceptionInstance->getTrace() as $idx => $traceArray) { + // Init argument string + $argsString = ''; + + // Convert arguments type into human-readable + foreach ($traceArray['args'] as $arg) { + $argsString .= ', ' . gettype($arg); + } // END - foreach + $argsString = substr($argsString, 2); + + // Set missing file/line + if (!isset($traceArray['file'])) $traceArray['file'] = 'unknown'; + if (!isset($traceArray['line'])) $traceArray['line'] = '0'; + if (!isset($traceArray['class'])) $traceArray['class'] = 'UnknownObject'; + if (!isset($traceArray['type'])) $traceArray['type'] = '->'; + + $backTrace .= sprintf("---------- Pos %d: ---------- +Method : %s%s%s(%s) +----- Caller: ----- +File : %s +Line : %d\n", + ($idx + 1), + $traceArray['class'], + $traceArray['type'], + $traceArray['function'], + $argsString, + basename($traceArray['file']), + $traceArray['line'] + ); + } // END - foreach + + // Construct the message + $message = sprintf("-------------------------------------------------------------------------------- +Uncaught Exception : %s +-------------------------------------------------------------------------------- +Message : %s +Code : %s +File : %s +Line : %d +-------------------------------------------------------------------------------- +Backtrace: +-------------------------------------------------------------------------------- +%s +--------------------------------------------------------------------------------\n", + trim(html_entity_decode(strip_tags($exceptionInstance->__toString()))), + trim(html_entity_decode(strip_tags($exceptionInstance->getMessage()))), + $exceptionInstance->getHexCode(), + $exceptionInstance->getFile(), + $exceptionInstance->getLine(), + trim($backTrace) + ); + + // Output the message + print($message); + } else { + // Invalid exception instance detected! Do *only* throw exceptions that + // extends our own exception 'FrameworkException' to get such nice + // outputs like above. + print('exceptionInstance[]=' . gettype($exceptionInstance) . ' is invalid! Please inform the core developer team.'); + } +} + +// Error handler +function __errorHandler ($errno, $errstr, $errfile, $errline, array $errcontext) { + // Construct the message + $message = sprintf('File: %s, Line: %s, Code: %s, Message: %s', + basename($errfile), + $errline, + $errno, + $errstr + ); + + // Throw an exception here + throw new FatalErrorException($message, BaseFrameworkSystem::EXCEPTION_FATAL_ERROR); +} // END - function + +// Assertion handler +function __assertHandler ($file, $line, $code) { + // Empty code? + if ($code === '') { + $code = 'Unknown'; + } // END - if + + // Create message + $message = sprintf('File: %s, Line: %s, Code: %s', + basename($file), + $line, + $code + ); + + // Log assert + syslog(LOG_WARNING, $message); + + // Throw an exception here + throw new AssertionException($message, BaseFrameworkSystem::EXCEPTION_ASSERTION_FAILED); +} // END - function + +// Set error handler +//set_error_handler('__errorHandler'); + +// Set the new handler +set_exception_handler('tests_exception_handler'); + +// Init assert handling +assert_options(ASSERT_ACTIVE , TRUE); +assert_options(ASSERT_WARNING , FALSE); +assert_options(ASSERT_BAIL , TRUE); +assert_options(ASSERT_QUIET_EVAL, FALSE); +assert_options(ASSERT_CALLBACK , '__assertHandler'); + +// [EOF] +?> diff --git a/application/tests/init.php b/application/tests/init.php new file mode 100644 index 00000000..71950028 --- /dev/null +++ b/application/tests/init.php @@ -0,0 +1,38 @@ + + * @version 0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// Get config instance +$cfg = FrameworkConfiguration::getSelfInstance(); + +// Initialize output system +require($cfg->getConfigEntry('base_path') . 'inc/output.php'); + +// This application needs a database connection then we have to simply include +// the inc/database.php script +require($cfg->getConfigEntry('base_path') . 'inc/database.php'); + +// [EOF] +?> diff --git a/application/tests/loader.php b/application/tests/loader.php new file mode 100644 index 00000000..53765f5c --- /dev/null +++ b/application/tests/loader.php @@ -0,0 +1,28 @@ + + * @version 0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// Scan for application's classes, exceptions and interfaces +ClassLoader::scanApplicationClasses(); + +// [EOF] +?> diff --git a/application/tests/rand.php b/application/tests/rand.php new file mode 100644 index 00000000..ddd36e68 --- /dev/null +++ b/application/tests/rand.php @@ -0,0 +1,25 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// Is there an application helper instance? We need the method main() for +// maining the application +$app = call_user_func_array( + array( + FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_helper_class'), 'getSelfInstance' + ), array() +); + +// Some sanity checks +if ((empty($app)) || (is_null($app))) { + // Something went wrong! + ApplicationEntryPoint::app_exit(sprintf("[Main:] The application %s could not be launched because the helper class %s is not loaded.", + $application, + FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_helper_class') + )); +} elseif (!is_object($app)) { + // No object! + ApplicationEntryPoint::app_exit(sprintf("[Main:] The application %s could not be launched because 'app' is not an object.", + $application + )); +} elseif (!method_exists($app, FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method'))) { + // Method not found! + ApplicationEntryPoint::app_exit(sprintf("[Main:] The application %s could not be launched because the method %s is missing.", + $application, + FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method') + )); +} + +// Call user function +call_user_func_array(array($app, FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method')), array()); + +// [EOF] +?> diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 9ff3c04b..25e0986f 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -223,6 +223,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $socketResource = FALSE; + /** + * Regular expression to use for validation + */ + private $regularExpression = ''; + /** * Package data */ @@ -1081,6 +1086,27 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { return $this->socketResource; } + /** + * Setter for regular expression + * + * @param $regularExpression A valid regular expression + * @return void + */ + public final function setRegularExpression ($regularExpression) { + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': regularExpression=' . $regularExpression . ',previous[' . gettype($this->regularExpression) . ']=' . $this->regularExpression); + $this->regularExpression = $regularExpression; + } + + /** + * Getter for regular expression + * + * @return $regularExpression A valid regular expression + */ + public final function getRegularExpression () { + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': regularExpression[' . gettype($this->regularExpression) . ']=' . $this->regularExpression); + return $this->regularExpression; + } + /** * Setter for helper instance * diff --git a/index.php b/index.php new file mode 100644 index 00000000..ebd9cba1 --- /dev/null +++ b/index.php @@ -0,0 +1,220 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +final class ApplicationEntryPoint { + /** + * Core path + */ + private static $corePath = ''; + + /** + * The application's emergency exit + * + * @param $message The optional message we shall output on exit + * @param $code Error code from exception + * @param $extraData Extra information from exceptions + * @param $silentMode Whether silent mode is turned on + * @return void + * @todo This method is old code and needs heavy rewrite and should be moved to ApplicationHelper + */ + public static final function app_exit ($message = '', $code = FALSE, $extraData = '', $silentMode = FALSE) { + // Is this method already called? + if (isset($GLOBALS['app_die_called'])) { + // Then output the text directly + exit($message); + } // END - if + + // This method shall not be called twice + $GLOBALS['app_die_called'] = TRUE; + + // Is a message set? + if (empty($message)) { + // No message provided + $message = 'No message provided.'; + } // END - if + + // Get config instance + $configInstance = FrameworkConfiguration::getSelfInstance(); + + // Do we have debug installation? + if (($configInstance->getConfigEntry('product_install_mode') == 'productive') || ($silentMode === TRUE)) { + // Abort here + exit(); + } // END - if + + // Get some instances + $tpl = FrameworkConfiguration::getSelfInstance()->getConfigEntry('web_template_class'); + $languageInstance = LanguageSystem::getSelfInstance(); + + // Initialize template instance here to avoid warnings in IDE + $templateInstance = NULL; + + // Get response instance + $responseInstance = ApplicationHelper::getSelfInstance()->getResponseInstance(); + + // Is the template engine loaded? + if ((class_exists($tpl)) && (is_object($languageInstance))) { + // Use the template engine for putting out (nicer look) the message + try { + // Get the template instance from our object factory + $templateInstance = ObjectFactory::createObjectByName($tpl); + } catch (FrameworkException $e) { + exit(sprintf("[Main:] Could not initialize template engine for reason: %s", + $e->getMessage() + )); + } + + // Get and prepare backtrace for output + $backtraceArray = debug_backtrace(); + $backtrace = ''; + foreach ($backtraceArray as $key => $trace) { + // Set missing array elements + if (!isset($trace['file'])) { + $trace['file'] = __FILE__; + } // END - if + if (!isset($trace['line'])) { + $trace['line'] = __LINE__; + } // END - if + if (!isset($trace['args'])) { + $trace['args'] = array(); + } // END - if + + // Add the traceback path to the final output + $backtrace .= sprintf("%s:%d, %s(%d)
\n", + basename($trace['file']), + $trace['line'], + $trace['function'], + count($trace['args']) + ); + } // END - foreach + + // Init application instance + $applicationInstance = NULL; + + // Is the class there? + if (class_exists('ApplicationHelper')) { + // Get application instance + $applicationInstance = ApplicationHelper::getSelfInstance(); + + // Assign application data + $templateInstance->assignApplicationData($applicationInstance); + } // END - if + + // We only try this + try { + // Assign variables + $templateInstance->assignVariable('message', $message); + $templateInstance->assignVariable('code', $code); + $templateInstance->assignVariable('extra', $extraData); + $templateInstance->assignVariable('backtrace', $backtrace); + $templateInstance->assignVariable('total_includes', ClassLoader::getSelfInstance()->getTotal()); + $templateInstance->assignVariable('total_objects', ObjectFactory::getTotal()); + $templateInstance->assignVariable('title', $languageInstance->getMessage('emergency_exit_title')); + + // Load the template + $templateInstance->loadCodeTemplate('emergency_exit'); + + // Compile the template + $templateInstance->compileTemplate(); + + // Compile all variables + $templateInstance->compileVariables(); + + // Transfer data to response + $templateInstance->transferToResponse($responseInstance); + + // Flush the response + $responseInstance->flushBuffer(); + } catch (FileIoException $e) { + // Even the template 'emergency_exit' wasn't found so output both message + exit($message . ', exception: ' . $e->getMessage()); + } + + // Good bye... + exit(); + } else { + // Output message and die + exit(sprintf('[Main:] Emergency exit reached: %s', + $message + )); + } + } + + /** + * Determines the correct absolute path for all includes only once per run. + * Other calls of this method are being "cached". + * + * @return $corePath Base path (core) for all includes + */ + protected static final function detectCorePath () { + // Is it not set? + if (empty(self::$corePath)) { + // Auto-detect our core path + self::$corePath = str_replace("\\", '/', dirname(__FILE__)); + } // END - if + + // Return it + return self::$corePath; + } + + /** + * The application's main entry point. This class isolates some local + * variables which shall not become visible to outside because of security + * concerns. We are doing this here to "emulate" the well-known entry + * point in Java. + * + * @return void + */ + public static final function main () { + // Load config file + require(self::detectCorePath() . '/inc/config.php'); + + // Load all include files + require($cfg->getConfigEntry('base_path') . 'inc/includes.php'); + + // Load all framework classes + require($cfg->getConfigEntry('base_path') . 'inc/classes.php'); + + // Include the application selector + require($cfg->getConfigEntry('base_path') . 'inc/selector.php'); + } // END - main() +} // END - class + +// Developer mode active? Comment out if no dev! +define('DEVELOPER', TRUE); + +// Log all exceptions (only debug! This option can create large error logs) +//define('LOG_EXCEPTIONS', TRUE); + +//xdebug_start_trace(); + +// Do not remove the following line: +ApplicationEntryPoint::main(); + +// [EOF] +?>