Continued:
authorRoland Haeder <roland@mxchange.org>
Tue, 20 Jan 2015 21:45:58 +0000 (22:45 +0100)
committerRoland Haeder <roland@mxchange.org>
Tue, 20 Jan 2015 21:45:58 +0000 (22:45 +0100)
- 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 <roland@mxchange.org>
13 files changed:
application/.htaccess [new file with mode: 0644]
application/tests/.htaccess [new file with mode: 0644]
application/tests/class_ApplicationHelper.php [new file with mode: 0644]
application/tests/config.php [new file with mode: 0644]
application/tests/data.php [new file with mode: 0644]
application/tests/debug.php [new file with mode: 0644]
application/tests/exceptions.php [new file with mode: 0644]
application/tests/init.php [new file with mode: 0644]
application/tests/loader.php [new file with mode: 0644]
application/tests/rand.php [new file with mode: 0644]
application/tests/starter.php [new file with mode: 0644]
inc/classes/main/class_BaseFrameworkSystem.php
index.php [new file with mode: 0644]

diff --git a/application/.htaccess b/application/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/tests/.htaccess b/application/tests/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/tests/class_ApplicationHelper.php b/application/tests/class_ApplicationHelper.php
new file mode 100644 (file)
index 0000000..f05d1d9
--- /dev/null
@@ -0,0 +1,234 @@
+<?php
+/**
+ * A class holding general data about the application and some methods for
+ * the management including the entry point.
+ *
+ * E.g.:
+ *
+ * index.php?app=my_app
+ *
+ * You need to create a folder in the folder "application" named "my_app"
+ * (without the quotes) and create a include file called
+ * class_ApplicationHelper.php. You have to write the same class for your
+ * application and implement the same interface called ManageableApplication
+ * because this class include file will be searched for.
+ *
+ * It is good when you avoid more GET parameters to keep URLs short and sweet.
+ * But sometimes you need some GET paramerers e.g. for your imprint or info page
+ * or other linked pages which you have to create and state some informations.
+ *
+ * Please remember that this include file is being loaded *before* the class
+ * loader is loading classes from "exceptions", "interfaces" and "main"!
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 0000000..477c7e1
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Configuration entries for this application only
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+
+// 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 (file)
index 0000000..f8aa236
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Application data
+ *
+ * Please remember that this include file is being loaded *before* the class
+ * loader is loading classes from "exceptions", "interfaces" and "main"!
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+
+// 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 (file)
index 0000000..a27fdb4
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/**
+ * Initialize some debug constants here
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+
+// 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 (file)
index 0000000..e483daf
--- /dev/null
@@ -0,0 +1,143 @@
+<?php
+/**
+ * An include file for setting up the exception handler of test suite
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+
+// 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 = '<em>Unknown</em>';
+       } // 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 (file)
index 0000000..7195002
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Application initializer
+ *
+ * Please remember that this include file is being loaded *before* the class
+ * loader is loading classes from "exceptions", "interfaces" and "main"!
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+
+// 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 (file)
index 0000000..53765f5
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/**
+ * The application's class loader
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+
+// 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 (file)
index 0000000..ddd36e6
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+$rands = array();
+$max_iter = 500000;
+$max_rand = 200000;
+
+print 'max_iter=' . $max_iter . ',max_rand=' . $max_rand . PHP_EOL;
+
+for ($idx = 0; $idx < $max_iter; $idx++) {
+       $number = mt_rand(0, $max_rand);
+       if (isset($rands['mt_rand'][$number])) {
+               $rands['mt_rand'][$number]++;
+       } else {
+               $rands['mt_rand'][$number] = 1;
+       }
+
+       $number = rand(0, $max_rand);
+       if (isset($rands['rand'][$number])) {
+               $rands['rand'][$number]++;
+       } else {
+               $rands['rand'][$number] = 1;
+       }
+}
+
+print 'mt_rand=' . count($rands['mt_rand']) . PHP_EOL;
+print 'rand=' . count($rands['rand']) . PHP_EOL;
diff --git a/application/tests/starter.php b/application/tests/starter.php
new file mode 100644 (file)
index 0000000..007a85b
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/**
+ * The application launcher
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+
+// 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 <span class=\"app_name\">%s</span> could not be launched because the helper class <span class=\"class_name\">%s</span> is not loaded.",
+               $application,
+               FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_helper_class')
+       ));
+} elseif (!is_object($app)) {
+       // No object!
+       ApplicationEntryPoint::app_exit(sprintf("[Main:] The application <span class=\"app_name\">%s</span> could not be launched because &#39;app&#39; is not an object.",
+               $application
+       ));
+} elseif (!method_exists($app, FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method'))) {
+       // Method not found!
+       ApplicationEntryPoint::app_exit(sprintf("[Main:] The application <span class=\"app_name\">%s</span> could not be launched because the method <span class=\"method_name\">%s</span> is missing.",
+               $application,
+               FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method')
+       ));
+}
+
+// Call user function
+call_user_func_array(array($app, FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method')), array());
+
+// [EOF]
+?>
index 9ff3c04..25e0986 100644 (file)
@@ -224,6 +224,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        private $socketResource = FALSE;
 
        /**
+        * Regular expression to use for validation
+        */
+       private $regularExpression = '';
+
+       /**
         * Package data
         */
        private $packageData = array();
@@ -1082,6 +1087,27 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        }
 
        /**
+        * 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
         *
         * @param       $helperInstance         An instance of a helper class
diff --git a/index.php b/index.php
new file mode 100644 (file)
index 0000000..ebd9cba
--- /dev/null
+++ b/index.php
@@ -0,0 +1,220 @@
+<?php
+/**
+ * The main class with the entry point to the whole application. This class
+ * "emulates" Java's entry point call. Additionally it covers local
+ * variables from outside access to prevent possible attacks on uninitialized
+ * local variables.
+ *
+ * But good little boys and girls would always initialize their variables... ;-)
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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: <span class=\"exception_reason\">%s</span>",
+                                       $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("<span class=\"backtrace_file\">%s</span>:%d, <span class=\"backtrace_function\">%s(%d)</span><br />\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: <span class="emergency_span">%s</span>',
+                               $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]
+?>