From 65d72098d3ec6a0ef7782668264fc6f33f9ebeb6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 9 Jun 2008 18:14:14 +0000 Subject: [PATCH] eval() commands replace by improved object factory, user login class stub added --- .gitattributes | 5 + application/selector/init.php | 11 +- application/ship-simu/config.php | 3 + application/ship-simu/init.php | 8 +- application/ship-simu/loader.php | 8 +- application/ship-simu/main/class_ | 2 +- .../ship-simu/main/class_WorksContract.php | 109 ++++-------------- application/ship-simu/main/login/.htaccess | 1 + .../main/login/class_ShipSimuUserLogin.php | 72 ++++++++++++ .../class_ShipSimuRegistration.php | 6 +- .../ship-simu/main/ships/class_BaseShip.php | 16 +-- inc/classes/interfaces/login/.htaccess | 1 + .../interfaces/login/class_LoginableUser.php | 37 ++++++ inc/classes/main/actions/class_ | 6 +- .../class_LoginAfterRegistrationAction.php | 85 ++++++++++++++ inc/classes/main/class_ | 6 +- .../main/class_BaseFrameworkSystem.php | 67 +++-------- inc/classes/main/commands/class_ | 2 +- inc/classes/main/controller/class_ | 2 +- inc/classes/main/database/class_ | 2 +- .../extended/class_SerializationContainer.php | 15 +-- .../factories/objects/class_ObjectFactory.php | 24 ++-- inc/classes/main/filter/class_ | 2 +- .../resolver/web/class_WebCommandResolver.php | 14 +-- .../web/class_WebControllerResolver.php | 20 +--- .../compressor/class_CompressorChannel.php | 39 ++----- .../debug/class_DebugMiddleware.php | 63 +++++----- inc/config.php | 3 + 28 files changed, 336 insertions(+), 293 deletions(-) create mode 100644 application/ship-simu/main/login/.htaccess create mode 100644 application/ship-simu/main/login/class_ShipSimuUserLogin.php create mode 100644 inc/classes/interfaces/login/.htaccess create mode 100644 inc/classes/interfaces/login/class_LoginableUser.php create mode 100644 inc/classes/main/actions/post_registration/class_LoginAfterRegistrationAction.php diff --git a/.gitattributes b/.gitattributes index 64cbe6f..4435563 100644 --- a/.gitattributes +++ b/.gitattributes @@ -82,6 +82,8 @@ application/ship-simu/main/drives/motor/.htaccess -text application/ship-simu/main/drives/motor/class_Motor.php -text application/ship-simu/main/factories/.htaccess -text application/ship-simu/main/factories/class_ShipSimuWebNewsFactory.php -text +application/ship-simu/main/login/.htaccess -text +application/ship-simu/main/login/class_ShipSimuUserLogin.php -text application/ship-simu/main/parts/.htaccess -text application/ship-simu/main/parts/class_BaseShipPart.php -text application/ship-simu/main/parts/maschineroom/.htaccess -text @@ -260,6 +262,8 @@ inc/classes/interfaces/io/output/.htaccess -text inc/classes/interfaces/io/output/class_OutputStreamer.php -text inc/classes/interfaces/language/.htaccess -text inc/classes/interfaces/language/class_ManageableLanguage.php -text +inc/classes/interfaces/login/.htaccess -text +inc/classes/interfaces/login/class_LoginableUser.php -text inc/classes/interfaces/registration/.htaccess -text inc/classes/interfaces/registration/class_UserRegister.php -text inc/classes/interfaces/registry/.htaccess -text @@ -282,6 +286,7 @@ inc/classes/main/actions/.htaccess -text inc/classes/main/actions/class_ -text inc/classes/main/actions/class_BaseAction.php -text inc/classes/main/actions/post_registration/.htaccess -text +inc/classes/main/actions/post_registration/class_LoginAfterRegistrationAction.php -text inc/classes/main/cache/.htaccess -text inc/classes/main/cache/class_MemoryCache.php -text inc/classes/main/class_ -text diff --git a/application/selector/init.php b/application/selector/init.php index 6a02f97..ed31055 100644 --- a/application/selector/init.php +++ b/application/selector/init.php @@ -24,13 +24,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -// -// -// Get an instance of the initializer -$eval = sprintf("\$app = %s::getInstance();", + +// Generate call-back function +$callback = sprintf("%s::getInstance", FrameworkConfiguration::getInstance()->readConfig('app_helper_class') ); -eval($eval); + +// Get an instance of the helper +$app = call_user_func_array($callback, array()); // Set application name and version $app->setAppName("Applikationsauswähler"); diff --git a/application/ship-simu/config.php b/application/ship-simu/config.php index 1b3b1a2..2d5cd1f 100644 --- a/application/ship-simu/config.php +++ b/application/ship-simu/config.php @@ -73,6 +73,9 @@ $cfg->setConfigEntry('command_parameter', "page"); // CFG: USER-REGISTRATION $cfg->setConfigEntry('user_registration', "ShipSimuRegistration"); +// CFG: LOGIN-USER +$cfg->setConfigEntry('login_user', "ShipSimuUserLogin"); + // CFG: USER-STATUS-REGISTER $cfg->setConfigEntry('user_status_register', "UNCONFIRMED"); diff --git a/application/ship-simu/init.php b/application/ship-simu/init.php index ffc577c..431e442 100644 --- a/application/ship-simu/init.php +++ b/application/ship-simu/init.php @@ -33,11 +33,13 @@ * along with this program. If not, see . */ -// Get an instance of the helper -$eval = sprintf("\$app = %s::getInstance();", +// Generate call-back function +$callback = sprintf("%s::getInstance", FrameworkConfiguration::getInstance()->readConfig('app_helper_class') ); -eval($eval); + +// Get an instance of the helper +$app = call_user_func_array($callback, array()); // Set application name and version $app->setAppName("Ship-Simu Schiffsimulator"); diff --git a/application/ship-simu/loader.php b/application/ship-simu/loader.php index 35ecc29..240c01a 100644 --- a/application/ship-simu/loader.php +++ b/application/ship-simu/loader.php @@ -34,25 +34,25 @@ foreach ($lowerClasses as $class) { try { ClassLoader::getInstance()->loadClasses(sprintf("%s/%s/%s", FrameworkConfiguration::getInstance()->readConfig('application_path'), $application, $class)); } catch (PathIsNoDirectoryException $e) { - ApplicationEntryPoint::app_die(sprintf("[Main:%s] Kann Applikationsklassen im Pfad %s nicht laden. Grund: %s", + ApplicationEntryPoint::app_die(sprintf("[Main:%s] Cannot find application classes in path %s for this reason: %s", $application, $class, $e->getMessage() )); } catch (PathIsEmptyException $e) { - ApplicationEntryPoint::app_die(sprintf("[Main:%s] Kann Applikationsklassen im Pfad %s nicht laden. Grund: %s", + ApplicationEntryPoint::app_die(sprintf("[Main:%s] Cannot find application classes in path %s for this reason: %s", $application, $class, $e->getMessage() )); } catch (PathReadProtectedException $e) { - ApplicationEntryPoint::app_die(sprintf("[Main:%s] Kann Applikationsklassen im Pfad %s nicht laden. Grund: %s", + ApplicationEntryPoint::app_die(sprintf("[Main:%s] Cannot find application classes in path %s for this reason: %s", $application, $class, $e->getMessage() )); } catch (DirPointerNotOpenedException $e) { - ApplicationEntryPoint::app_die(sprintf("[Main:%s] Kann Applikationsklassen im Pfad %s nicht laden. Grund: %s", + ApplicationEntryPoint::app_die(sprintf("[Main:%s] Cannot find application classes in path %s for this reason: %s", $application, $class, $e->getMessage() diff --git a/application/ship-simu/main/class_ b/application/ship-simu/main/class_ index d8eb3ef..7623572 100644 --- a/application/ship-simu/main/class_ +++ b/application/ship-simu/main/class_ @@ -35,7 +35,7 @@ class extends BaseFrameworkSystem { $this->setObjectDescription(""); // Create unique ID number - $this->createUniqueID(); + $this->generateUniqueId(); // Clean up a little $this->removeNumberFormaters(); diff --git a/application/ship-simu/main/class_WorksContract.php b/application/ship-simu/main/class_WorksContract.php index d1cf574..ebed512 100644 --- a/application/ship-simu/main/class_WorksContract.php +++ b/application/ship-simu/main/class_WorksContract.php @@ -61,18 +61,6 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { $shipType = (string) $shipType; $shipName = (string) $shipName; - // Is the other one a contract partner? - if (is_null($partnerInstance)) { - // Opps! Empty partner instance? - throw new NullPointerException($partnerInstance, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!is_object($partnerInstance)) { - // Not an object! ;-( - throw new NoObjectException($partnerInstance, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!method_exists($partnerInstance, 'isContractPartner')) { - // Does not have the required feature (method) - throw new MissingMethodException(array($partnerInstance, 'isContractPartner'), self::EXCEPTION_MISSING_METHOD); - } - // Get new instance $contractInstance = new WorksContract(); @@ -95,21 +83,11 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { } // Schiff-Instanz temporaer erzeugen und in den Bauvertrag einfuegen - $eval = sprintf("\$contractInstance->setShipInstance(%s::create%s(\"%s\"));", - $shipType, - $shipType, - $shipName - ); - - // Debug message - if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $contractInstance->getDebugInstance()->output(sprintf("[%s:%d] Konstruierte PHP-Anweisung:
%s

\n", - __CLASS__, - __LINE__, - htmlentities($eval) - )); + $shipInstance = ObjectFactory::createObjectByName($shipType, array($shipName)); + $contractInstance->setShipInstance($shipInstance); - // Execute constructed command - @eval($eval); + // Remove the ship instance + unset($shipInstance); // Set itself as contract partner $contractInstance->setContractPartner($partnerInstance); @@ -172,71 +150,28 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { )); // Initialize the instance (shall not be done within dynamic part) - $instance = null; - - // Prepare the big command for everthing - $eval = "try { - \$instance = ".$shipPart."::create".$shipPart."("; - foreach ($dataArray as $pIdx => $parts) { - if (is_string($parts)) { - // String einbauen - $eval .= "\"".$parts."\", "; - } elseif (is_array($parts)) { - // Ist ein weiteres Array! - $eval .= "array("; - foreach ($parts as $idx2 => $sub) { - $eval .= "'".$idx2."' => "; - if (is_string($sub)) { - // Ist erneut ein String - $eval .= "\"".$sub."\""; - } elseif (is_array($sub)) { - // Wird nicht mehr unterstuetzt! - ApplicationEntryPoint::app_die("No more arrays!"); - } else { - // Direkt anhaengen - $eval .= $sub; - } - $eval .= ", "; - } - - // Letztes Komma entfernen - $eval = substr($eval, 0, -2); - $eval .= "), "; - } else { - // Etwas anderes direkt! - $eval .= $parts.", "; - } - } + $partInstance = null; - // Letztes Komma abhaengen - $eval = substr($eval, 0, -2); - $eval .= "); -} catch (DimNotFoundInArrayException \$e) { - \$this->getDebugInstance()->output(sprintf(\"[main:] Die %s konnte nicht vervollständigt werden. Grund: %s
\\n\", - \$this->getShipInstance()->getShipName(), - \$e->getMessage() - )); - \$instance = null; -}"; - - // Debug message - if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[Ship:] Konstruierte PHP-Anweisung:
%s

\n", - htmlentities($eval) - )); - - // Code ausfuhren - @eval($eval); - - // Try to add the ship part to the contract + // Try to get an instance for this ship part try { + $partInstance = ObjectFactory::createObjectByName($shipPart, $dataArray); + } catch (DimNotFoundInArrayException $e) { + $this->getDebugInstance()->output(sprintf("[main:] Die %s konnte nicht vervollständigt werden. Grund: %s
", + $this->getShipInstance()->getShipName(), + $e->getMessage() + )); + + // Debug message if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Versuche ein Schiffsteil in den Bauvertrag aufzunehmen.
\n", __CLASS__, __LINE__ )); - if (!$instance instanceof ConstructableShipPart) { + + // Is this ship part constructable? + if (!$partInstance instanceof ConstructableShipPart) { // Ship part not constructable! throw new ShipPartNotConstructableException(array($shipPart), self::EXCEPTION_NOT_CONSTRUCTABLE); - } elseif (!$this->getShipInstance()->createShipPart($instance, $parentPart)) { + } elseif (!$this->getShipInstance()->createShipPart($partInstance, $parentPart)) { // Schiff konnte nicht gebaut werden! throw new ShipNotConstructedException(sprintf("Das Schiff %s konnte wegen eines Fehlers nicht gebaut werden. Siehe obere Meldungen.", $this->getShipInstance()->getShipName() @@ -248,24 +183,24 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { } // Get price for this item - $price = $this->getMerchantInstance()->getPriceFromList($instance); + $price = $this->getMerchantInstance()->getPriceFromList($partInstance); // Final debug message if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] %s kostet %s.
\n", __CLASS__, __LINE__, - $instance->getObjectDescription(), + $partInstance->getObjectDescription(), $this->getMerchantInstance()->formatCurrency($price) )); // Add price - $instance->setPrice($price); + $partInstance->setPrice($price); // Final debug message if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] %s wurde in den Bauvertrag aufgenommen.
\n", __CLASS__, __LINE__, - $instance->getObjectDescription() + $partInstance->getObjectDescription() )); } diff --git a/application/ship-simu/main/login/.htaccess b/application/ship-simu/main/login/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/ship-simu/main/login/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/ship-simu/main/login/class_ShipSimuUserLogin.php b/application/ship-simu/main/login/class_ShipSimuUserLogin.php new file mode 100644 index 0000000..2ffc777 --- /dev/null +++ b/application/ship-simu/main/login/class_ShipSimuUserLogin.php @@ -0,0 +1,72 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.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 . + */ +class ShipSimuUserLogin extends BaseFrameworkSystem implements LoginableUser { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Login for Ship-Simu"); + + // Create unique ID number + $this->generateUniqueId(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this login class + * + * @return $loginInstance An instance of this login class + */ + public final static function createShipSimuUserLogin () { + // Get a new instance + $loginInstance = new ShipSimuUserLogin(); + + // Return the instance + return $loginInstance; + } + + /** + * Logins the user with the given request containing the credential. The + * result of the login can be thrown by exception or, if prefered stored + * in a boolean attribute which is then readable by a matching getter. + * + * @param $requestInstance An instance of a Requestable class + * @return void + */ + public function doLogin (Requestable $requestInstance) { + $this->partialStub(); + } +} + +// [EOF] +?> diff --git a/application/ship-simu/main/registration/class_ShipSimuRegistration.php b/application/ship-simu/main/registration/class_ShipSimuRegistration.php index 01235f7..0a8563c 100644 --- a/application/ship-simu/main/registration/class_ShipSimuRegistration.php +++ b/application/ship-simu/main/registration/class_ShipSimuRegistration.php @@ -142,7 +142,11 @@ class ShipSimuRegistration extends BaseRegistration { * @return void */ public function doPostAction () { - $this->partialStub(); + // Get an action instance from our factory + $actionInstance = ObjectFactory::createObjectByConfiguredName('post_registration_action'); + + // Execute the action + $actionInstance->execute($this->getRequestInstance(), $this->getResponseInstance()); } /** diff --git a/application/ship-simu/main/ships/class_BaseShip.php b/application/ship-simu/main/ships/class_BaseShip.php index 77426cc..7ccfaff 100644 --- a/application/ship-simu/main/ships/class_BaseShip.php +++ b/application/ship-simu/main/ships/class_BaseShip.php @@ -71,20 +71,8 @@ class BaseShip extends BaseSimulator { // Ist die gewuenschte Klasse vorhanden? if (class_exists($partClass)) { - // Befehl zusammenbauen - $eval = sprintf("\$partInstance = %s::create%s();", - $partClass, $partClass - ); - - // Debug-Meldung ausgeben - if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruierte PHP-Anweisung:
%s

\n", - __CLASS__, - __LINE__, - htmlentities($eval) - )); - - // ... und ausfuehren - eval($eval); + // Get an instance back from our object factory + $partInstance = ObjectFactory::createObjectByName($partClass); } else { // Nicht vorhanden, dann Ausnahme werfen! throw new ClassNotFoundException($partClass, self::EXCEPTION_CLASS_NOT_FOUND); diff --git a/inc/classes/interfaces/login/.htaccess b/inc/classes/interfaces/login/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/interfaces/login/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/login/class_LoginableUser.php b/inc/classes/interfaces/login/class_LoginableUser.php new file mode 100644 index 0000000..c7abf2d --- /dev/null +++ b/inc/classes/interfaces/login/class_LoginableUser.php @@ -0,0 +1,37 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.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 . + */ +interface LoginableUser extends FrameworkInterface { + /** + * Logins the user with the given request containing the credential. The + * result of the login can be thrown by exception or, if prefered stored + * in a boolean attribute which is then readable by a matching getter. + * + * @param $requestInstance An instance of a Requestable class + * @return void + */ + function doLogin (Requestable $requestInstance); +} + +// +?> diff --git a/inc/classes/main/actions/class_ b/inc/classes/main/actions/class_ index 797b770..93d4fc5 100644 --- a/inc/classes/main/actions/class_ +++ b/inc/classes/main/actions/class_ @@ -3,10 +3,10 @@ * * * @author Roland Haeder - * @version 0.3.0 + * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version - * @link http://www.mxchange.org + * @link http://www.ship-simu.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 @@ -35,7 +35,7 @@ class ???Action extends BaseAction implements Commandable { $this->setObjectDescription(""); // Generate unique key - $this->createUniqueID(); + $this->generateUniqueId(); } /** diff --git a/inc/classes/main/actions/post_registration/class_LoginAfterRegistrationAction.php b/inc/classes/main/actions/post_registration/class_LoginAfterRegistrationAction.php new file mode 100644 index 0000000..aae33eb --- /dev/null +++ b/inc/classes/main/actions/post_registration/class_LoginAfterRegistrationAction.php @@ -0,0 +1,85 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.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 . + */ +class LoginAfterRegistrationAction extends BaseAction implements Commandable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set description + $this->setObjectDescription("Post registration action for logging in"); + + // Generate unique key + $this->generateUniqueId(); + } + + /** + * Creates an instance of this action + * + * @return $actionInstance An instance of this action class + */ + public final static function createLoginAfterRegistrationAction () { + // Get a new instance + $actionInstance = new LoginAfterRegistrationAction(); + + // Return the instance + return $actionInstance; + } + + /** + * Executes the command with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get a login class from factory + $loginInstance = ObjectFactory::createObjectByConfiguredName('login_user'); + + // Login the user by the request instance + $loginInstance->doLogin($requestInstance); + + // Was the login fine? Then redirect here + if ($loginInstance->ifLoginWasSuccessfull()) { + // Try to redirect here + try { + $responseInstance->redirectConfiguredUrl('app_login'); + } catch (FrameworkException $e) { + // Something went wrong here! + $responseInstance->addFatalMessage($e->getMessage()); + } + } else { + // Attach error message to the response + $responseInstance->addFatalMessage('failed_login_after_registration'); + } + } +} + +// [EOF] +?> diff --git a/inc/classes/main/class_ b/inc/classes/main/class_ index 07d96db..6a6ff22 100644 --- a/inc/classes/main/class_ +++ b/inc/classes/main/class_ @@ -3,10 +3,10 @@ * * * @author Roland Haeder - * @version 0.3.0 + * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version - * @link http://www.mxchange.org + * @link http://www.ship-simu.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 @@ -35,7 +35,7 @@ class extends BaseFrameworkSystem { $this->setObjectDescription(""); // Create unique ID number - $this->createUniqueID(); + $this->generateUniqueId(); // Clean up a little $this->removeNumberFormaters(); diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index f61deb8..7fc55e2 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -293,26 +293,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { if (is_null($this->getDebugInstance())) { // Set the debug output system if it is not debug class ;) $this->setDebugInstance(DebugMiddleware::createDebugMiddleware($this->getConfigInstance()->readConfig('debug_engine'))); - } + } // END - if // Initialize web instance - if (is_null($this->getWebOutputInstance())) { - // Generate the eval() command - $eval = sprintf("\$this->setWebOutputInstance(%s::create%s(\"%s\"));", - $this->getConfigInstance()->readConfig('web_engine'), - $this->getConfigInstance()->readConfig('web_engine'), - $this->getConfigInstance()->readConfig('web_content_type') - ); - - // Debug message - if (defined('DEBUG_EVAL')) $this->getDebugInstance()->output(sprintf("[%s:] Constructed PHP command:
%s

\n", - $this->__toString(), - htmlentities($eval) - )); + if ((is_null($this->getWebOutputInstance())) && ($this->__toString() != "ObjectFactory")) { + // Call our object factory + $outputInstance = ObjectFactory::createObjectByConfiguredName('web_engine', array($this->getConfigInstance()->readConfig('web_content_type'))); - // Run the command - eval($eval); - } + // And set the instance + $this->setWebOutputInstance($outputInstance); + } // END - if // Initialize compressor channel if (is_null($this->getCompressorChannel())) { @@ -321,7 +311,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { PATH, $this->getConfigInstance()->readConfig('compressor_base_path') ))); - } + } // END - if // Initialize database middleware if (is_null($this->getDatabaseInstance())) { @@ -330,16 +320,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { if (is_object($db)) { // Set the database middleware $this->setDatabaseInstance($db); - } - } - } + } // END - if + } // END - if + } // END - if } /** * Setter for language instance * - * @param $configInstance The configuration instance which shall - * be FrameworkConfiguration + * @param $configInstance The configuration instance which shall + * be FrameworkConfiguration * @return void */ public final function setConfigInstance (FrameworkConfiguration $configInstance) { @@ -858,36 +848,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } // Initialize the template engine - $tplEngine = null; - $eval = sprintf("\$tplEngine = %s::create%s( - \"%s\", - \$appInstance->getLanguageInstance(), - \$appInstance->getFileIoInstance() -);", - $this->getConfigInstance()->readConfig('tpl_engine'), - $this->getConfigInstance()->readConfig('tpl_engine'), - $fqfn - ); - - // Debug message - if ((!is_null($this->getDebugInstance())) && (defined('DEBUG_EVAL'))) { - $this->getDebugInstance()->output(sprintf("[%s:] Constructed PHP command:
%s

\n", - $this->__toString(), - htmlentities($eval) - )); - } - - // Run the command - eval($eval); - - // Is it a valid instance? - if (is_null($tplEngine)) { - // No class returned - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!$tplEngine instanceof CompileableTemplate) { - // Not an object! ;-( - throw new UnsupportedTemplateEngineException($tplEngine, self::EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED); - } + $tplEngine = ObjectFactory::createObjectByConfiguredName('tpl_engine', array($fqfn, $appInstance->getLanguageInstance(), $appInstance->getFileIoInstance())); // Return the prepared instance return $tplEngine; diff --git a/inc/classes/main/commands/class_ b/inc/classes/main/commands/class_ index cbb5b60..628cd0f 100644 --- a/inc/classes/main/commands/class_ +++ b/inc/classes/main/commands/class_ @@ -35,7 +35,7 @@ class ???Command extends BaseCommand implements Commandable { $this->setObjectDescription(""); // Create unique ID number - $this->createUniqueID(); + $this->generateUniqueId(); // Clean up a little $this->removeSystemArray(); diff --git a/inc/classes/main/controller/class_ b/inc/classes/main/controller/class_ index 0f9c56c..46459d5 100644 --- a/inc/classes/main/controller/class_ +++ b/inc/classes/main/controller/class_ @@ -35,7 +35,7 @@ class Controller extends BaseController implements Controller { $this->setObjectDescription("Ein spezieller Controller"); // Create unique ID number - $this->createUniqueID(); + $this->generateUniqueId(); // Clean up a little $this->removeSystemArray(); diff --git a/inc/classes/main/database/class_ b/inc/classes/main/database/class_ index 657fbd0..6c338fd 100644 --- a/inc/classes/main/database/class_ +++ b/inc/classes/main/database/class_ @@ -36,7 +36,7 @@ class extends BaseDatabaseFrontend { $this->setObjectDescription(""); // Create unique ID number - $this->createUniqueID(); + $this->generateUniqueId(); // Clean up a little $this->removeNumberFormaters(); diff --git a/inc/classes/main/extended/class_SerializationContainer.php b/inc/classes/main/extended/class_SerializationContainer.php index 54a4acb..6d5c15d 100644 --- a/inc/classes/main/extended/class_SerializationContainer.php +++ b/inc/classes/main/extended/class_SerializationContainer.php @@ -55,19 +55,8 @@ class SerializationContainer extends FrameworkArrayObject { // Is the required method available? if (method_exists($object, sprintf("get%s", $curr))) { - // Generate a command for getting it - $eval = sprintf("\$value = \$object->get%s();", - $curr - ); - - // Debug eval command - if (defined('DEBUG_EVAL')) $limitInstance->getDebugInstance()->output(sprintf("[%s:] Constructed PHP command:
%s

\n", - $this->__toString(), - htmlentities($eval) - )); - - // Run it - eval($eval); + // Generate call-back function + $value = call_user_func_array(array($object, sprintf("get%s", $curr))); // Add this item to the container list $containerInstance->append(array( diff --git a/inc/classes/main/factories/objects/class_ObjectFactory.php b/inc/classes/main/factories/objects/class_ObjectFactory.php index 19d0e3d..8fe592b 100644 --- a/inc/classes/main/factories/objects/class_ObjectFactory.php +++ b/inc/classes/main/factories/objects/class_ObjectFactory.php @@ -43,12 +43,13 @@ class ObjectFactory extends BaseFactory { * the class was not found. No parameters for the object are currently * supported. * - * @param $className Name of the class we shall construct - * @return $objectInstance An instance of the requested object + * @param $className Name of the class we shall construct + * @param $args Arguments in an indexed array + * @return $objectInstance An instance of the requested object * @throws ClassNotFoundException If the requested class was not found * @throws EmptyVariableException If a variable is empty unexpectly */ - public final static function createObjectByName ($className) { + public final static function createObjectByName ($className, array $args=array()) { // First get an instance of this factory $factoryInstance = new ObjectFactory(); @@ -61,14 +62,14 @@ class ObjectFactory extends BaseFactory { throw new ClassNotFoundException(array($factoryInstance, $className), self::EXCEPTION_CLASS_NOT_FOUND); } - // Then Prepare the eval() command - $eval = sprintf("\$objectInstance = %s::create%s();", + // Then Prepare the call-back function + $callback = sprintf("%s::create%s", $className, $className ); - // Run the command - eval($eval); + // Run the user function + $objectInstance = call_user_func_array($callback, $args); // Return the prepared instance return $objectInstance; @@ -77,15 +78,16 @@ class ObjectFactory extends BaseFactory { /** * Creates an object by it's configured name * - * @param $configEnttry Configuration entry to read - * @return $objectInstance An instance of the requested object + * @param $configEnttry Configuration entry to read + * @param $args Arguments in an indexed array + * @return $objectInstance An instance of the requested object */ - public final static function createObjectByConfiguredName ($configEntry) { + public final static function createObjectByConfiguredName ($configEntry, array $args=array()) { // Read the configuration entry $className = FrameworkConfiguration::getInstance()->readConfig($configEntry); // Send this to the other factory... - $objectInstance = self::createObjectByName($className); + $objectInstance = self::createObjectByName($className, $args); // Return the instance return $objectInstance; diff --git a/inc/classes/main/filter/class_ b/inc/classes/main/filter/class_ index a1feab9..6741599 100644 --- a/inc/classes/main/filter/class_ +++ b/inc/classes/main/filter/class_ @@ -35,7 +35,7 @@ class ???Filter extends BaseFrameworkSystem implements Filterable { $this->setObjectDescription("A concrete filter"); // Create unique ID number - $this->createUniqueID(); + $this->generateUniqueId(); // Clean up a little $this->removeNumberFormaters(); diff --git a/inc/classes/main/resolver/web/class_WebCommandResolver.php b/inc/classes/main/resolver/web/class_WebCommandResolver.php index bcc6dbb..fa52125 100644 --- a/inc/classes/main/resolver/web/class_WebCommandResolver.php +++ b/inc/classes/main/resolver/web/class_WebCommandResolver.php @@ -184,19 +184,7 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { } // Initiate the command - $eval = sprintf("\$commandInstance = %s::create%s(\$this);", - $className, - $className - ); - - // Run the command - eval($eval); - - // Is the instance valid? - if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) { - // Something is wrong - $commandInstance = null; - } + $commandInstance = ObjectFactory::createObjectByName($className, array($this)); // Return the result return $commandInstance; diff --git a/inc/classes/main/resolver/web/class_WebControllerResolver.php b/inc/classes/main/resolver/web/class_WebControllerResolver.php index 7da1934..b5f66e8 100644 --- a/inc/classes/main/resolver/web/class_WebControllerResolver.php +++ b/inc/classes/main/resolver/web/class_WebControllerResolver.php @@ -173,22 +173,14 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { // Still not found? throw new DefaultControllerException($this, self::EXCEPTION_DEFAUL_CONTROLLER_GONE); } - } - - // Initiate the controller - $eval = sprintf("\$controllerInstance = %s::create%s(WebCommandResolver::createWebCommandResolver(\$commandName, \$this->getApplicationInstance()));", - $class, - $class - ); + } // END - if - // Run the command - eval($eval); + // Initiate the resolver and controller + $resolverInstance = ObjectFactory::createObjectByConfiguredName('web_cmd_resolver', array($commandName, $this->getApplicationInstance())); + $controllerInstance = ObjectFactory::createObjectByName($class, array($resolverInstance)); - // Is the instance valid? - if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) { - // Something is wrong - $controllerInstance = null; - } + // Remove resolver + unset($resolverInstance); // Return the result return $controllerInstance; diff --git a/inc/classes/middleware/compressor/class_CompressorChannel.php b/inc/classes/middleware/compressor/class_CompressorChannel.php index 51ea53e..1a99985 100644 --- a/inc/classes/middleware/compressor/class_CompressorChannel.php +++ b/inc/classes/middleware/compressor/class_CompressorChannel.php @@ -73,35 +73,20 @@ class CompressorChannel extends BaseMiddleware { // must keep on class in one file. $class = substr($dir, 6, -4); - // Create eval command - $eval = sprintf("\$tempInstance = %s::create%s();", - $class, - $class - ); - - // Debug message - if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $cInstance->getDebugInstance()->output(sprintf("[%s:] Konstruierte PHP-Anweisung:
%s

\n", - $cInstance->__toString(), - htmlentities($eval) - )); - - // Run it. This will create an instance to the current class - eval($eval); - - // Is the instance valid? We have the stream handler here - if ((!is_null($tempInstance)) && (method_exists($tempInstance, 'compressStream')) && (method_exists($tempInstance, 'decompressStream'))) { - // Okay, this handler is valid - $cInstance->setCompressor($tempInstance); - - // No more searches required because we have found a valid compressor stream - break; - } - } - } + // Get an instance from our object factory + $tempInstance = ObjectFactory::createObjectByName($class); + + // Set the compressor + $cInstance->setCompressor($tempInstance); + + // No more searches required because we have found a valid compressor stream + break; + } // END - if + } // END - while // Close the directory $dirPointer->closeDirectory(); - } + } // END - if // Check again if there is a compressor if ( @@ -112,7 +97,7 @@ class CompressorChannel extends BaseMiddleware { ) { // Set the null compressor handler. This should not be configureable! $cInstance->setCompressor(ObjectFactory::createObjectByName('NullCompressor')); - } + } // END - if // Return the compressor instance return $cInstance; diff --git a/inc/classes/middleware/debug/class_DebugMiddleware.php b/inc/classes/middleware/debug/class_DebugMiddleware.php index bbd96b5..5c1e050 100644 --- a/inc/classes/middleware/debug/class_DebugMiddleware.php +++ b/inc/classes/middleware/debug/class_DebugMiddleware.php @@ -27,7 +27,7 @@ class DebugMiddleware extends BaseMiddleware { /** * The concrete output instance */ - private $outputHandler = null; + private $outputInstance = null; /** * An instance of this class @@ -44,7 +44,7 @@ class DebugMiddleware extends BaseMiddleware { parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Debug-Ausgabe-Handler"); + $this->setObjectDescription("Debug-Ausgabe-Instance"); // Create an unique ID $this->generateUniqueId(); @@ -58,36 +58,24 @@ class DebugMiddleware extends BaseMiddleware { * If no output is given this class is currently being used for back-fall. * This fall-back mechanism will become deprecated very soon. * - * @param $debuggerClass The class name which we shall use for + * @param $debuggerClass The class name which we shall use for * registering the *real* debug output - * @return $debugInstance An instance of this middleware class + * @return $debugInstance An instance of this middleware class */ public final static function createDebugMiddleware ($debuggerClass) { // Create an instance if this middleware $debugInstance = new DebugMiddleware(); - // Is there a valid output handler provided? - if ((!is_null($debuggerClass)) && (is_object($debuggerClass)) && (method_exists($debuggerClass, 'outputStream'))) { - // Use the given output system - $debugInstance->setOutputHandler($debuggerClass); + // Is there a valid output instance provided? + if ((!is_null($debuggerClass)) && (is_object($debuggerClass)) && ($debuggerClass instanceof OutputStreamer)) { + // Use the given output instance + $debugInstance->setOutputInstance($debuggerClass); } elseif ((!is_null($debuggerClass)) && (is_string($debuggerClass)) && (class_exists($debuggerClass))) { // A name for a debug output class has been provided so we try to get it - $eval = sprintf("\$debuggerClass = %s::create%s();", - $debuggerClass, - $debuggerClass - ); + $debuggerInstance = ObjectFactory::createObjectByName($debuggerClass); - // Run the constructed name - @eval($eval); - - // Was this successfull? - if ((is_object($debuggerClass)) && (method_exists($debuggerClass, "outputStream"))) { - // Set this as output class - $debugInstance->setOutputHandler($debuggerClass); - } else { - // No object or method is missing use fall-back - throw new MissingMethodException(array($debuggerClass, 'outputStream'), self::EXCEPTION_MISSING_METHOD); - } + // Set this as output class + $debugInstance->setOutputInstance($debuggerInstance); } // Return instance @@ -104,32 +92,33 @@ class DebugMiddleware extends BaseMiddleware { } /** - * Setter for output handler + * Setter for output instance * + * @param $outputInstance The debug output instance * @return void */ - public final function setOutputHandler ($outputHandler) { - $this->outputHandler = $outputHandler; + public final function setOutputInstance (OutputStreamer $outputInstance) { + $this->outputInstance = $outputInstance; } /** * This method shall send debug output which can be HTML code for the * browser or debug lines for a log file, etc. to the registered debug - * output handler. + * output instance. * * @return void */ public final function output ($outStream) { - // Check if the output handler is valid - if (is_null($this->outputHandler)) { - // Debug output handler was not set + // Check if the output instance is valid + if (is_null($this->outputInstance)) { + // Debug output instance was not set throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!is_object($this->outputHandler)) { - // The debug output handler is not an object - throw new NoObjectException($this->ouputHandler, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!method_exists($this->outputHandler, 'outputStream')) { + } elseif (!is_object($this->outputInstance)) { + // The debug output instance is not an object + throw new NoObjectException($this->ouputInstance, self::EXCEPTION_IS_NO_OBJECT); + } elseif (!method_exists($this->outputInstance, 'outputStream')) { // The required method outputStream() is missing - throw new MissingMethodException(array($this->outputHandler, 'outputStream'), self::EXCEPTION_MISSING_METHOD); + throw new MissingMethodException(array($this->outputInstance, 'outputStream'), self::EXCEPTION_MISSING_METHOD); } // Is the output stream set @@ -138,8 +127,8 @@ class DebugMiddleware extends BaseMiddleware { return; } - // Use the output handler - $this->outputHandler->outputStream($outStream); + // Use the output instance + $this->outputInstance->outputStream($outStream); } } diff --git a/inc/config.php b/inc/config.php index dc48fe6..142093b 100644 --- a/inc/config.php +++ b/inc/config.php @@ -189,6 +189,9 @@ $cfg->setConfigEntry('rng_class', "RandomNumberGenerator"); // CFG: USER-DB-WRAPPER $cfg->setConfigEntry('user_db_wrapper', "UserDatabaseWrapper"); +// CFG: WEB-CMD-RESOLVER +$cfg->setConfigEntry('web_cmd_resolver', "WebCommandResolver"); + // CFG: MATH-PRIME $cfg->setConfigEntry('math_prime', 591623); -- 2.39.2