<?php
+// Must be this namespace, else the launcher cannot find the class.
+namespace Org\Mxchange\CoreFramework\Helper\Application;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Loader\ClassLoader;
+use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
+use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Registry\Registerable;
+use Org\Mxchange\CoreFramework\Registry\Registry;
+use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
+
/**
* A class holding general data about the application and some methods for
* the management including the entry point.
*
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0
- * @copyright Copyright (c) 2015, 2016 City Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 City Developer Team
* @license GNU GPL 3.0 or any newer version
*
* This program is free software: you can redistribute it and/or modify
}
/**
- * Launches the test suite
+ * 1) Setups application data
*
* @return void
*/
- public final function entryPoint () {
- // Set this application in registry
- Registry::getRegistry()->addInstance('app', $this);
+ public function setupApplicationData () {
+ // Set all application data
+ $this->setAppName('Unit tests and more');
+ $this->setAppVersion('0.0.0');
+ $this->setAppShortName('tests');
+ }
- // Default response is console
- $response = self::getResponseTypeFromSystem();
- $responseType = self::getResponseTypeFromSystem();
+ /**
+ * 2) Does initial stuff before starting the application
+ *
+ * @return void
+ */
+ public function initApplication () {
+ // Get config instance
+ $cfg = FrameworkBootstrap::getConfigurationInstance();
- // Create a new request object
- $requestInstance = ObjectFactory::createObjectByName(self::convertToClassName($response) . 'Request');
+ // Initialize output system
+ self::createDebugInstance('ApplicationHelper');
- // Remember request instance here
- $this->setRequestInstance($requestInstance);
+ /*
+ * This application needs a database connection then simply call init
+ * method.
+ */
+ FrameworkBootstrap::initDatabaseInstance();
- // Do we have another response?
- if ($requestInstance->isRequestElementSet('request')) {
- // Then use it
- $response = strtolower($requestInstance->getRequestElement('request'));
- $responseType = $response;
- } // END - if
+ // Register core tests
+ ClassLoader::registerTestsPath('framework/main/tests');
- // ... and a new response object
- $responseClass = sprintf('%sResponse', self::convertToClassName($response));
- $responseInstance = ObjectFactory::createObjectByName($responseClass, array($this));
+ // Register own tests
+ ClassLoader::registerTestsPath('application/tests/tests');
- // Remember response instance here
- $this->setResponseInstance($responseInstance);
+ // Scan for them now
+ ClassLoader::scanTestsClasses();
+ }
+
+ /**
+ * 3) Launches the application
+ *
+ * @return void
+ */
+ public function launchApplication () {
+ // Get request/response instances
+ $requestInstance = FrameworkBootstrap::getRequestInstance();
+ $responseInstance = FrameworkBootstrap::getResponseInstance();
// Get the parameter from the request
$commandName = $requestInstance->getRequestElement('command');
} // END - if
// Get a controller resolver
- $resolverClass = self::convertToClassName($this->getAppShortName() . '_' . $responseType . '_controller_resolver');
+ $resolverClass = sprintf(
+ 'Org\Mxchange\CoreFramework\Tests\Resolver\Controller\%s',
+ self::convertToClassName(sprintf(
+ '%s_%s_controller_resolver',
+ $this->getAppShortName(),
+ FrameworkBootstrap::getRequestTypeFromSystem()
+ ))
+ );
$resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this));
// Get a controller instance as well
$this->setControllerInstance($resolverInstance->resolveController());
- // Initialize language system
- $languageInstance = ObjectFactory::createObjectByConfiguredName('language_system_class');
-
- // And set it here
- $this->setLanguageInstance($languageInstance);
-
- // Launch the game here
+ // Launch the test suite here
$this->getControllerInstance()->handleRequest($requestInstance, $responseInstance);
// -------------------------- Shutdown phase --------------------------
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown in progress ...');
$this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance);
- }
-
- /**
- * Assigns extra application-depending data
- *
- * @param $templateInstance An instance of a CompileableTemplate
- * @return void
- * @todo Nothing to add?
- */
- public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)');
}
/**
public function buildMasterTemplateName () {
return 'city_main';
}
-}
-// [EOF]
-?>
+ /**
+ * Assigns extra application-depending data
+ *
+ * @param $templateInstance An instance of a CompileableTemplate
+ * @return void
+ * @todo Nothing to add?
+ */
+ public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
+ $this->partialStub('Unfinished method. templateInstance=' . $templateInstance->__toString());
+ }
+
+}
// Unfinished method
}
}
-
-// [EOF]
-?>
// Unfinished method
}
}
-
-// [EOF]
-?>
// Unfinished method
}
}
-
-// [EOF]
-?>
// Unfinished method
}
}
-
-// [EOF]
-?>
$controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_status_filter'));
}
}
-
-// [EOF]
-?>
$controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_status_filter'));
}
}
-
-// [EOF]
-?>
$controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_status_filter'));
}
}
-
-// [EOF]
-?>
// Unfinished method
}
}
-
-// [EOF]
-?>
$this->partialStub('Please add some tasks or empty this method.');
}
}
-
-// [EOF]
-?>
$sectionsInstance->expandMaps();
}
}
-
-// [EOF]
-?>
$this->partialStub('Please add some tasks or empty this method.');
}
}
-
-// [EOF]
-?>
return $!!!Instance;
}
}
-
-// [EOF]
-?>
parent::__construct($className);
}
}
-
-// [EOF]
-?>
$this->cityInstance = $cityInstance;
}
}
-
-// [EOF]
-?>
$controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('city_daemon_shutdown_city_filter'));
}
}
-
-// [EOF]
-?>
$controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('captcha_guest_verifier_filter'));
}
}
-
-// [EOF]
-?>
//$controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('email_validator_filter'));
}
}
-
-// [EOF]
-?>
$controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('birthday_register_verifier_filter'));
}
}
-
-// [EOF]
-?>
$controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('captcha_user_verifier_filter'));
}
}
-
-// [EOF]
-?>
// Empty for now
}
}
-
-// [EOF]
-?>
//$controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('node_php_requirements_filter'));
}
}
-
-// [EOF]
-?>
Registry::getRegistry()->addInstance('action', $actionInstance);
}
}
-
-// [EOF]
-?>
// Set title
$templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('page_login_title'));
- // Construct the menu in every command. We could do this in BaseCommand class. But this means
- // *every* command has a navigation system and that is want we don't want.
+ /*
+ * Construct the menu in every command. We could do this in BaseCommand class. But this means
+ * *every* command has a navigation system and that is want we don't want.
+ */
$menuInstance = ObjectFactory::createObjectByConfiguredName('login_menu_class', array($applicationInstance));
// Render the menu
// Empty for now
}
}
-
-// [EOF]
-?>
// Empty for now
}
}
-
-// [EOF]
-?>
// Empty for now
}
}
-
-// [EOF]
-?>
public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
}
}
-
-// [EOF]
-?>
$controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_unconfirmed_filter'));
}
}
-
-// [EOF]
-?>
// Empty for now
}
}
-
-// [EOF]
-?>
$this->executeFilters('activation', $requestInstance, $responseInstance);
}
}
-
-// [EOF]
-?>
$this->executeGenericPrePostCommand($requestInstance, $responseInstance);
}
}
-
-// [EOF]
-?>
$this->executeGenericPrePostCommand($requestInstance, $responseInstance);
}
}
-
-// [EOF]
-?>
$this->executeGenericPrePostCommand($requestInstance, $responseInstance);
}
}
-
-// [EOF]
-?>
$responseInstance->flushBuffer();
}
}
-
-// [EOF]
-?>
$responseInstance->flushBuffer();
}
}
-
-// [EOF]
-?>
$this->executeGenericPrePostCommand($requestInstance, $responseInstance);
}
}
-
-// [EOF]
-?>
$this->executeGenericPrePostCommand($requestInstance, $responseInstance);
}
}
-
-// [EOF]
-?>
$responseInstance->flushBuffer();
}
}
-
-// [EOF]
-?>
$this->genericHanleRequestLoginAreaFailedRedirect($requestInstance, $responseInstance);
}
}
-
-// [EOF]
-?>
return $cityIds;
}
}
-
-// [EOF]
-?>
return $isFound;
}
}
-
-// [EOF]
-?>
return $isFound;
}
}
-
-// [EOF]
-?>
self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: A total of ' . $totalSections . ' sections has been written for city id ' . $cityId . '.');
}
}
-
-// [EOF]
-?>
return $wrapperInstance;
}
}
-
-// [EOF]
-?>
assert($this->ifRegionExists($regionName));
}
}
-
-// [EOF]
-?>
assert($this->ifRegionExists($regionName));
}
}
-
-// [EOF]
-?>
return $cityInstance;
}
}
-
-// [EOF]
-?>
return $managerInstance;
}
}
-
-// [EOF]
-?>
return $stateInstance;
}
}
-
-// [EOF]
-?>
$this->partialStub('Please implement this step.');
}
}
-
-// [EOF]
-?>
$cityInstance->doBootstrapping();
}
}
-
-// [EOF]
-?>
$this->partialStub('Please implement this step.');
}
}
-
-// [EOF]
-?>
$cityInstance->bootstrapInitCityDaemon();
}
}
-
-// [EOF]
-?>
$this->partialStub('Please implement this method.');
}
}
-
-// [EOF]
-?>
/* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CITY-INIT-FILTER[' . __METHOD__ . ':' . __LINE__ . ']: City daemon has been added to registry.');
}
}
-
-// [EOF]
-?>
} // END - if
}
}
-
-// [EOF]
-?>
$cityInstance->outputConsoleTeaser();
}
}
-
-// [EOF]
-?>
$this->partialStub('Please implement this step.');
}
}
-
-// [EOF]
-?>
$packageInstance->getStackInstance()->pushNamed(NetworkPackage::STACKER_NAME_PROCESSED_MESSAGE, $messageArray);
}
}
-
-// [EOF]
-?>
$this->partialStub('Please implement this step.');
}
}
-
-// [EOF]
-?>
$cityInstance->doShutdown();
}
}
-
-// [EOF]
-?>
$handlerInstance->doShutdown();
}
}
-
-// [EOF]
-?>
$cityInstance->addExtraTasks($handlerInstance);
}
}
-
-// [EOF]
-?>
return $alreadyTaken;
}
}
-
-// [EOF]
-?>
} // END - if
}
}
-
-// [EOF]
-?>
} // END - if
}
}
-
-// [EOF]
-?>
$this->partialStub('Please implement this method.');
}
}
-
-// [EOF]
-?>
return $managerInstance;
}
}
-
-// [EOF]
-?>
return $managerInstance;
}
}
-
-// [EOF]
-?>
} // END - foreach
}
}
-
-// [EOF]
-?>
return $managerInstance;
}
}
-
-// [EOF]
-?>
parent::__construct($className);
}
}
-
-// [EOF]
-?>
return $resultInstance;
}
}
-
-// [EOF]
-?>
return $resultInstance;
}
}
-
-// [EOF]
-?>
die('!ok');
}
}
-
-// [EOF]
-?>
return $menuInstance;
}
}
-
-// [EOF]
-?>
return $menuInstance;
}
}
-
-// [EOF]
-?>
return $menuInstance;
}
}
-
-// [EOF]
-?>
return $menuInstance;
}
}
-
-// [EOF]
-?>
return $menuInstance;
}
}
-
-// [EOF]
-?>
return $menuInstance;
}
}
-
-// [EOF]
-?>
return $menuInstance;
}
}
-
-// [EOF]
-?>
return $menuInstance;
}
}
-
-// [EOF]
-?>
return $menuInstance;
}
}
-
-// [EOF]
-?>
return $menuInstance;
}
}
-
-// [EOF]
-?>
return $resolverInstance;
}
}
-
-// [EOF]
-?>
return $resolverInstance;
}
}
-
-// [EOF]
-?>
return $resolverInstance;
}
}
-
-// [EOF]
-?>
return $resolverInstance;
}
}
-
-// [EOF]
-?>
return $resolverInstance;
}
}
-
-// [EOF]
-?>
return $stateInstance;
}
}
-
-// [EOF]
-?>
return $stateInstance;
}
}
-
-// [EOF]
-?>
} // END - if
}
}
-
-// [EOF]
-?>
CityStateFactory::createCityStateInstanceByName('active');
}
}
-
-// [EOF]
-?>
$this->cityInstance = $cityInstance;
}
}
-
-// [EOF]
-?>
self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
}
}
-
-// [EOF]
-?>
self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
}
}
-
-// [EOF]
-?>
self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
}
}
-
-// [EOF]
-?>
self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
}
}
-
-// [EOF]
-?>
// CFG: CITY-FOO
$cfg->setConfigEntry('city_foo', 'foo');
-
-// [EOF]
-?>
<?php
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+
/**
* Configuration entries for this application only
*
*/
// Some hub-specific configuration like port hostname where we will listen, etc.
-$cfg = FrameworkConfiguration::getSelfInstance();
+$cfg = FrameworkBootstrap::getConfigurationInstance();
/******************************************************************************
* General *
// CFG: CITY-MAX-INITIAL-DOWN-EXPANSION
$cfg->setConfigEntry('city_max_initial_down_expansion', 3);
-
-// [EOF]
-?>
<?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) 2015, 2016 City 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('Simple City Growth Simulation');
-$app->setAppVersion('0.0.0');
-$app->setAppShortName('city');
-
-// [EOF]
-?>
+// @DEPRECATED
// Set error reporting
error_reporting(E_ALL | E_STRICT);
-
-// [EOF]
-?>
<?php
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Generic\FrameworkException;
+use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+
/**
* An include file for setting up the exception handler of test suite
*
* @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0
- * @copyright Copyright (c) 2015, 2016 City Developer Team
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
* @license GNU GPL 3.0 or any newer version
*
* This program is free software: you can redistribute it and/or modify
*/
// The node's own exception handler
-function city_exception_handler ($exceptionInstance) {
+function tests_exception_handler ($exceptionInstance) {
// Is it an object and a valid instance?
- if ((is_object($exceptionInstance)) && ($exceptionInstance instanceof FrameworkException)) {
+ if ((is_object($exceptionInstance)) && ($exceptionInstance instanceof Exception)) {
// Init variable
$backTrace = '';
--------------------------------------------------------------------------------
%s
--------------------------------------------------------------------------------\n",
- trim(html_entity_decode(strip_tags($exceptionInstance->__toString()))),
+ trim(html_entity_decode(strip_tags(get_class($exceptionInstance)))),
trim(html_entity_decode(strip_tags($exceptionInstance->getMessage()))),
- $exceptionInstance->getHexCode(),
+ ($exceptionInstance instanceof FrameworkException ? $exceptionInstance->getHexCode() : '0x' . bin2hex($exceptionInstance->getCode())),
$exceptionInstance->getFile(),
$exceptionInstance->getLine(),
trim($backTrace)
// Output the message
print($message);
+ } elseif (is_object($exceptionInstance)) {
+ // Output more details
+ printf('exceptionInstance=%s', print_r($exceptionInstance, true));
} 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 City developer team.');
+ /*
+ * Invalid exception instance detected! Do *only* throw exceptions that
+ * extends our own exception 'FrameworkException' to get such nice
+ * outputs like above.
+ */
+ printf('exceptionInstance[]=%s is invalid! Please inform the core developer team.' . PHP_EOL, gettype($exceptionInstance));
}
}
// Error handler
-function __errorHandler ($errno, $errstr, $errfile, $errline, array $errcontext) {
+function tests_error_handler ($errno, $errstr, $errfile, $errline, array $errcontext) {
// Construct the message
$message = sprintf('File: %s, Line: %s, Code: %s, Message: %s',
basename($errfile),
} // END - function
// Assertion handler
-function __assertHandler ($file, $line, $code) {
+function tests_assert_handler ($file, $line, $code) {
// Empty code?
if ($code === '') {
$code = '<em>Unknown</em>';
);
// Log assert
- die('message='.$message);
syslog(LOG_WARNING, $message);
// Throw an exception here
} // END - function
// Set error handler
-//set_error_handler('__errorHandler');
+//set_error_handler('tests_error_handler');
// Set the new handler
-set_exception_handler('city_exception_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]
-?>
+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 , 'tests_assert_handler');
<?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) 2015, 2016 City 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, you can use any class that expands BaseFrameworkSystem
-ApplicationHelper::createDebugInstance('ApplicationHelper');
-
-// 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]
-?>
+// @DEPRECATED
*/
function getAllCityIds ();
}
-
-// [EOF]
-?>
*/
function ifCityHasDistricts ($cityId);
}
-
-// [EOF]
-?>
*/
function ifCityHasLots ($cityId);
}
-
-// [EOF]
-?>
*/
function doInitialCityExpansion ($cityId);
}
-
-// [EOF]
-?>
*/
interface CityGameOptionsWrapper extends DatabaseWrapper {
}
-
-// [EOF]
-?>
*/
function createRegionByName ($regionName);
}
-
-// [EOF]
-?>
*/
interface RegionMapWrapper extends DatabaseWrapper {
}
-
-// [EOF]
-?>
*/
function isMapPendingExpansion ();
}
-
-// [EOF]
-?>
*/
function renderCityMap (HelpableTemplate $helperInstance);
}
-
-// [EOF]
-?>
*/
interface ManageableCityEntities extends Manageable {
}
-
-// [EOF]
-?>
*/
interface ManageableCityDistricts extends ManageableCityEntities {
}
-
-// [EOF]
-?>
*/
interface ManageableCityLots extends ManageableCityEntities {
}
-
-// [EOF]
-?>
*/
function expandMaps ();
}
-
-// [EOF]
-?>
*/
interface Manageable extends FrameworkInterface {
}
-
-// [EOF]
-?>
*/
function createFirstRegion ();
}
-
-// [EOF]
-?>
*/
function createRegionMapByResult (SearchableResult $resultInstance);
}
-
-// [EOF]
-?>
<?php
-/**
- * The application's class loader
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0
- * @copyright Copyright (c) 2015, 2016 City 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]
-?>
+// @DEPRECATED
<?php
-/**
- * The application launcher
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2015, 2016 City 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 '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 <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]
-?>
+// @DEPRECATED
// Comment this out if image is done
//$this->debugInstance();
-
-// [EOF]
-?>
// Comment this out if image is done
$this->debugInstance();
-
-// [EOF]
-?>
-Subproject commit 3136095b1d2e8c77eefd2eae23d99897ef586e56
+Subproject commit d3194bf4fa92124e55cfc596e50abca8e6303944
+++ /dev/null
-core/inc
\ No newline at end of file
<?php
+// Own namespace (watch out: core)
+namespace Org\Mxchange\CoreFramework\EntryPoint;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Filesystem\FileNotFoundException;
+use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
+use Org\Mxchange\CoreFramework\Localization\LanguageSystem;
+use Org\Mxchange\CoreFramework\Loader\ClassLoader;
+use Org\Mxchange\CoreFramework\Generic\FrameworkException;
+
+// Import SPL stuff
+use \Exception;
+
/**
* The main class with the entry point to the whole application. This class
* "emulates" Java's entry point call. Additionally it covers local
*
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.shipsimu.org
*
*/
final class ApplicationEntryPoint {
/**
- * Core path
+ * Framework path
*/
- private static $corePath = '';
+ private static $frameworkPath = '';
/**
* The application's emergency exit
* @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) {
+ public static final function exitApplication ($message = '', $code = false, $extraData = '', $silentMode = false) {
// Is this method already called?
if (isset($GLOBALS['app_die_called'])) {
// Then output the text directly
} // END - if
// This method shall not be called twice
- $GLOBALS['app_die_called'] = TRUE;
+ $GLOBALS['app_die_called'] = true;
// Is a message set?
if (empty($message)) {
} // END - if
// Get config instance
- $configInstance = FrameworkConfiguration::getSelfInstance();
+ $configInstance = FrameworkBootstrap::getConfigurationInstance();
// Do we have debug installation?
- if (($configInstance->getConfigEntry('product_install_mode') == 'productive') || ($silentMode === TRUE)) {
+ if (($configInstance->getConfigEntry('product_install_mode') == 'productive') || ($silentMode === true)) {
// Abort here
exit();
} // END - if
// Get some instances
- $tpl = FrameworkConfiguration::getSelfInstance()->getConfigEntry('html_template_class');
+ $tpl = $configInstance->getConfigEntry('html_template_class');
$languageInstance = LanguageSystem::getSelfInstance();
// Initialize template instance here to avoid warnings in IDE
$templateInstance = NULL;
// Get response instance
- $responseInstance = ApplicationHelper::getSelfInstance()->getResponseInstance();
+ $responseInstance = FrameworkBootstrap::getResponseInstance();
// Is the template engine loaded?
if ((class_exists($tpl)) && (is_object($languageInstance))) {
// 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>",
+ exit(sprintf('[Main:] Could not initialize template engine for reason: <span class="exception_reason">%s</span>',
$e->getMessage()
));
}
} // 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",
+ $backtrace .= sprintf('<span class="backtrace_file">%s</span>:%d, <span class="backtrace_function">%s(%d)</span><br />' . PHP_EOL,
basename($trace['file']),
$trace['line'],
$trace['function'],
$applicationInstance = NULL;
// Is the class there?
- if (class_exists('ApplicationHelper')) {
+ if (class_exists('Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper')) {
// Get application instance
$applicationInstance = ApplicationHelper::getSelfInstance();
// Flush the response
$responseInstance->flushBuffer();
- } catch (FileIoException $e) {
+ } catch (FileNotFoundException $e) {
// Even the template 'emergency_exit' wasn't found so output both message
exit($message . ', exception: ' . $e->getMessage());
}
}
/**
- * Determines the correct absolute path for all includes only once per run.
- * Other calls of this method are being "cached".
+ * Determines the correct absolute path for the framework. A set of common
+ * paths is being tested (first most common for applications, second when
+ * core tests are being executed and third/forth if the framework has been
+ * cloned there).
*
- * @return $corePath Base path (core) for all includes
+ * @return $frameworkPath Path for framework
*/
- protected static final function detectCorePath () {
+ public static final function detectFrameworkPath () {
// Is it not set?
- if (empty(self::$corePath)) {
- // Auto-detect our core path
- self::$corePath = str_replace("\\", '/', dirname(__FILE__));
+ if (empty(self::$frameworkPath)) {
+ // Auto-detect core path (first application-common)
+ foreach (array('core', __DIR__, '/usr/local/share/php/core', '/usr/share/php/core') as $possiblePath) {
+ // Create full path for testing
+ $realPath = realpath($possiblePath);
+
+ // Debug message
+ //* NOISY-DEBUG: */ printf('[%s:%d]: realPath[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($realPath), $realPath);
+
+ // Is it false?
+ if ($realPath === false) {
+ // Then, not found.
+ continue;
+ } // END - if
+
+ // Append framework path
+ $frameworkPath = sprintf('%s%sframework%s', $realPath, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
+
+ // First create full-qualified file name (FQFN) to framework/config-global.php
+ $configFile = $frameworkPath . 'config-global.php';
+
+ // Debug message
+ //* NOISY-DEBUG: */ printf('[%s:%d]: configFile=%s' . PHP_EOL, __METHOD__, __LINE__, $configFile);
+
+ // Is it readable?
+ if (is_readable($configFile)) {
+ // Found one
+ self::$frameworkPath = $frameworkPath;
+
+ // Abort here
+ break;
+ } // END - if
+ } // END - foreach
+
+ // Able to find?
+ if (!is_dir(self::$frameworkPath)) {
+ // Is no directory
+ throw new Exception('Cannot find framework.');
+ } // END - if
} // END - if
// Return it
- return self::$corePath;
+ return self::$frameworkPath;
}
/**
- * The application's main entry point. This class isolates some local
+ * Getter for root path
+ *
+ * @return $rootPath Root path
+ */
+ public static function getRootPath () {
+ // Get __DIR__, really simple and no detection
+ return __DIR__;
+ }
+
+ /**
+ * The framework'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.
+ * concerns. This is done 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 bootstrap file
+ require sprintf('%sbootstrap%sbootstrap.inc.php', self::detectFrameworkPath(), DIRECTORY_SEPARATOR);
- // Load all include files
- require($cfg->getConfigEntry('base_path') . 'inc/includes.php');
+ /*
+ * Initial bootstrap is done, continue with initialization of
+ * framework.
+ */
+ FrameworkBootstrap::initFramework();
- // Include the application selector
- require($cfg->getConfigEntry('base_path') . 'inc/selector.php');
- } // END - main()
-} // END - class
+ // Next initialize the detected application
+ FrameworkBootstrap::prepareApplication();
+
+ /*
+ * Last step is to start the application, this will also initialize and
+ * register the application instance in registry.
+ */
+ FrameworkBootstrap::startApplication();
+ }
+}
// Developer mode active? Comment out if no dev!
-define('DEVELOPER', TRUE);
+define('DEVELOPER', true);
// Log all exceptions (only debug! This option can create large error logs)
-//define('LOG_EXCEPTIONS', TRUE);
+//define('LOG_EXCEPTIONS', true);
-//* DEBUG: */ xdebug_start_trace();
+//xdebug_start_trace();
-// Do not remove the following line:
+// Call above main() method
ApplicationEntryPoint::main();
-
-// [EOF]
-?>