X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Fclass_BaseFrameworkSystem.php;h=07e0e601029ac0ee6f8ddb11a8218136ec5238b6;hb=2f930fd62f97e06a6b90afb971cce6343522f9b9;hp=350c97faa34c12a99f052bec9ad3c165e8d53aa1;hpb=aa76ddf7f1d5d302f1d752efcd113515ecf152a2;p=core.git diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index 350c97fa..07e0e601 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -1,53 +1,61 @@ . */ -class BaseFrameworkSystem extends stdClass implements FrameworkInterface { +abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterface { /** * Length of output from hash() */ @@ -168,11 +176,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $parserInstance = NULL; - /** - * A HandleableProtocol instance - */ - private $protocolInstance = NULL; - /** * A database wrapper instance */ @@ -183,16 +186,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $helperInstance = NULL; - /** - * An instance of a Source class - */ - private $sourceInstance = NULL; - - /** - * An instance of a UrlSource class - */ - private $urlSourceInstance = NULL; - /** * An instance of a InputStream class */ @@ -213,11 +206,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $visitorInstance = NULL; - /** - * DHT instance - */ - private $dhtInstance = NULL; - /** * An instance of a database wrapper class */ @@ -248,11 +236,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $directoryInstance = NULL; - /** - * An instance of a communicator - */ - private $communicatorInstance = NULL; - /** * The concrete output instance */ @@ -263,6 +246,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $stateInstance = NULL; + /** + * Registry instance (implementing Register) + */ + private $registryInstance = NULL; + + /** + * Call-back instance + */ + private $callbackInstance = NULL; + /** * Thousands separator */ @@ -303,11 +296,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $controllerName = ''; - /** - * Name of used protocol - */ - private $protocolName = 'invalid'; - /** * Array with bitmasks and such for pack/unpack methods to support both * 32-bit and 64-bit systems @@ -466,7 +454,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Set configuration instance if no registry ... if (!$this instanceof Register) { // ... because registries doesn't need to be configured - $this->setConfigInstance(FrameworkConfiguration::getSelfInstance()); + $this->setConfigInstance(FrameworkBootstrap::getConfigurationInstance()); } // END - if // Is the startup time set? (0 cannot be true anymore) @@ -788,7 +776,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return void */ public final function setConfigInstance (FrameworkConfiguration $configInstance) { - Registry::getRegistry()->addInstance('config', $configInstance); + GenericRegistry::getRegistry()->addInstance('config', $configInstance); } /** @@ -797,7 +785,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return $configInstance Configuration instance */ public final function getConfigInstance () { - $configInstance = Registry::getRegistry()->getInstance('config'); + $configInstance = GenericRegistry::getRegistry()->getInstance('config'); return $configInstance; } @@ -808,7 +796,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return void */ public final function setDebugInstance (DebugMiddleware $debugInstance) { - Registry::getRegistry()->addInstance('debug', $debugInstance); + GenericRegistry::getRegistry()->addInstance('debug', $debugInstance); } /** @@ -818,7 +806,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ public final function getDebugInstance () { // Get debug instance - $debugInstance = Registry::getRegistry()->getInstance('debug'); + $debugInstance = GenericRegistry::getRegistry()->getInstance('debug'); // Return it return $debugInstance; @@ -831,7 +819,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return void */ public final function setWebOutputInstance (OutputStreamer $webInstance) { - Registry::getRegistry()->addInstance('web_output', $webInstance); + GenericRegistry::getRegistry()->addInstance('web_output', $webInstance); } /** @@ -840,7 +828,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return $webOutputInstance - Instance to class WebOutput */ public final function getWebOutputInstance () { - $webOutputInstance = Registry::getRegistry()->getInstance('web_output'); + $webOutputInstance = GenericRegistry::getRegistry()->getInstance('web_output'); return $webOutputInstance; } @@ -851,7 +839,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return void */ public final function setDatabaseInstance (DatabaseConnection $databaseInstance) { - Registry::getRegistry()->addInstance('db_instance', $databaseInstance); + GenericRegistry::getRegistry()->addInstance('db_instance', $databaseInstance); } /** @@ -861,7 +849,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ public final function getDatabaseInstance () { // Get instance - $databaseInstance = Registry::getRegistry()->getInstance('db_instance'); + $databaseInstance = GenericRegistry::getRegistry()->getInstance('db_instance'); // Return instance return $databaseInstance; @@ -874,7 +862,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return void */ public final function setCompressorChannel (CompressorChannel $compressorInstance) { - Registry::getRegistry()->addInstance('compressor', $compressorInstance); + GenericRegistry::getRegistry()->addInstance('compressor', $compressorInstance); } /** @@ -883,7 +871,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return $compressorInstance The compressor channel */ public final function getCompressorChannel () { - $compressorInstance = Registry::getRegistry()->getInstance('compressor'); + $compressorInstance = GenericRegistry::getRegistry()->getInstance('compressor'); return $compressorInstance; } @@ -893,7 +881,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return $applicationInstance An instance of a manageable application helper class */ protected final function getApplicationInstance () { - $applicationInstance = Registry::getRegistry()->getInstance('app'); + $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); return $applicationInstance; } @@ -904,7 +892,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return void */ public final function setApplicationInstance (ManageableApplication $applicationInstance) { - Registry::getRegistry()->addInstance('application', $applicationInstance); + GenericRegistry::getRegistry()->addInstance('application', $applicationInstance); } /** @@ -913,7 +901,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return $langInstance An instance to the language sub-system */ protected final function getLanguageInstance () { - $langInstance = Registry::getRegistry()->getInstance('language'); + $langInstance = GenericRegistry::getRegistry()->getInstance('language'); return $langInstance; } @@ -925,7 +913,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @see LanguageSystem */ public final function setLanguageInstance (ManageableLanguage $langInstance) { - Registry::getRegistry()->addInstance('language', $langInstance); + GenericRegistry::getRegistry()->addInstance('language', $langInstance); } /** @@ -1137,25 +1125,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { return $this->parserInstance; } - /** - * Setter for HandleableProtocol instance - * - * @param $protocolInstance An instance of an HandleableProtocol - * @return void - */ - public final function setProtocolInstance (HandleableProtocol $protocolInstance) { - $this->protocolInstance = $protocolInstance; - } - - /** - * Getter for HandleableProtocol instance - * - * @return $protocolInstance An instance of an HandleableProtocol - */ - public final function getProtocolInstance () { - return $this->protocolInstance; - } - /** * Setter for DatabaseWrapper instance * @@ -1236,44 +1205,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { return $this->helperInstance; } - /** - * Setter for a Source instance - * - * @param $sourceInstance An instance of a Source class - * @return void - */ - protected final function setSourceInstance (Source $sourceInstance) { - $this->sourceInstance = $sourceInstance; - } - - /** - * Getter for a Source instance - * - * @return $sourceInstance An instance of a Source class - */ - protected final function getSourceInstance () { - return $this->sourceInstance; - } - - /** - * Setter for a UrlSource instance - * - * @param $sourceInstance An instance of a UrlSource class - * @return void - */ - protected final function setUrlSourceInstance (UrlSource $urlSourceInstance) { - $this->urlSourceInstance = $urlSourceInstance; - } - - /** - * Getter for a UrlSource instance - * - * @return $urlSourceInstance An instance of a UrlSource class - */ - protected final function getUrlSourceInstance () { - return $this->urlSourceInstance; - } - /** * Getter for a InputStream instance * @@ -1350,25 +1281,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { return $this->visitorInstance; } - /** - * Setter for DHT instance - * - * @param $dhtInstance A Distributable instance - * @return void - */ - protected final function setDhtInstance (Distributable $dhtInstance) { - $this->dhtInstance = $dhtInstance; - } - - /** - * Getter for DHT instance - * - * @return $dhtInstance A Distributable instance - */ - protected final function getDhtInstance () { - return $this->dhtInstance; - } - /** * Setter for raw package Data * @@ -1519,25 +1431,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { return $this->directoryInstance; } - /** - * Getter for communicator instance - * - * @return $communicatorInstance An instance of a Communicator class - */ - public final function getCommunicatorInstance () { - return $this->communicatorInstance; - } - - /** - * Setter for communicator instance - * - * @param $communicatorInstance An instance of a Communicator class - * @return void - */ - protected final function setCommunicatorInstance (Communicator $communicatorInstance) { - $this->communicatorInstance = $communicatorInstance; - } - /** * Setter for state instance * @@ -1576,6 +1469,44 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { return $this->outputInstance; } + /** + * Setter for registry instance + * + * @param $registryInstance An instance of a Register class + * @return void + */ + protected final function setRegistryInstance (Register $registryInstance) { + $this->registryInstance = $registryInstance; + } + + /** + * Getter for registry instance + * + * @return $registryInstance The debug registry instance + */ + public final function getRegistryInstance () { + return $this->registryInstance; + } + + /** + * Setter for call-back instance + * + * @param $callbackInstance An instance of a FrameworkInterface class + * @return void + */ + public final function setCallbackInstance (FrameworkInterface $callbackInstance) { + $this->callbackInstance = $callbackInstance; + } + + /** + * Getter for call-back instance + * + * @return $callbackInstance An instance of a FrameworkInterface class + */ + protected final function getCallbackInstance () { + return $this->callbackInstance; + } + /** * Setter for command name * @@ -1614,25 +1545,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { return $this->controllerName; } - /** - * Getter for protocol name - * - * @return $protocolName Name of used protocol - */ - public final function getProtocolName () { - return $this->protocolName; - } - - /** - * Setter for protocol name - * - * @param $protocolName Name of used protocol - * @return void - */ - protected final function setProtocolName ($protocolName) { - $this->protocolName = $protocolName; - } - /** * Checks whether an object equals this object. You should overwrite this * method to implement own equality checks @@ -1722,7 +1634,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Is the application instance set? if (is_null($applicationInstance)) { // Get the current instance - $applicationInstance = Registry::getRegistry()->getInstance('app'); + $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); // Still null? if (is_null($applicationInstance)) { @@ -1754,7 +1666,9 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Is a message set? if (!empty($message)) { // Construct message - $content = sprintf('
Message: %s
' . PHP_EOL, $message); + $content = sprintf('
+ Message: %s +
' . PHP_EOL, $message); } // END - if // Generate the output @@ -1767,7 +1681,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { ); // Output it - ApplicationEntryPoint::app_exit(sprintf('
%s debug output:
%s
Loaded includes:
%s
', + ApplicationEntryPoint::exitApplication(sprintf('
+ %s debug output: +
+
+ %s +
+Loaded includes: +
+ %s +
', $this->__toString(), $content, ClassLoader::getSelfInstance()->getPrintableIncludeList() @@ -1800,19 +1723,8 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return void */ protected function partialStub ($message = '') { - // Get the backtrace - $backtrace = debug_backtrace(); - - // Generate the class::method string - $methodName = 'UnknownClass->unknownMethod'; - if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) { - $methodName = $backtrace[1]['class'] . '->' . $backtrace[1]['function']; - } // END - if - - // Construct the full message - $stubMessage = sprintf('[%s]: Partial stub!', - $methodName - ); + // Init variable + $stubMessage = 'Partial Stub!'; // Is the extra message given? if (!empty($message)) { @@ -1865,14 +1777,14 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ public final static function createDebugInstance ($className, $lineNumber = NULL) { // Is the instance set? - if (!Registry::getRegistry()->instanceExists('debug')) { + if (!GenericRegistry::getRegistry()->instanceExists('debug')) { // Init debug instance $debugInstance = NULL; // Try it try { // Get a debugger instance - $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getSelfInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className); + $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className); } catch (NullPointerException $e) { // Didn't work, no instance there exit(sprintf('Cannot create debugInstance! Exception=%s,message=%s,className=%s,lineNumber=%d' . PHP_EOL, $e->__toString(), $e->getMessage(), $className, $lineNumber)); @@ -1881,11 +1793,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Empty string should be ignored and used for testing the middleware DebugMiddleware::getSelfInstance()->output(''); - // Set it in its own class. This will set it in the registry - $debugInstance->setDebugInstance($debugInstance); + // Set it in registry + GenericRegistry::getRegistry()->addInstance('debug', $debugInstance); } else { // Get instance from registry - $debugInstance = Registry::getRegistry()->getDebugInstance(); + $debugInstance = GenericRegistry::getRegistry()->getDebugInstance(); } // Return it @@ -1917,6 +1829,28 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Set debug instance to NULL $debugInstance = NULL; + // Get backtrace + $backtrace = debug_backtrace(!DEBUG_BACKTRACE_PROVIDE_OBJECT); + + // Is function partialStub/__callStatic ? + if (in_array($backtrace[1]['function'], array('partialStub', '__call', '__callStatic'))) { + // Prepend class::function:line from 3rd element + $message = sprintf('[%s::%s:%d]: %s', + $backtrace[2]['class'], + $backtrace[2]['function'], + (isset($backtrace[2]['line']) ? $backtrace[2]['line'] : '0'), + $message + ); + } else { + // Prepend class::function:line from 2nd element + $message = sprintf('[%s::%s:%d]: %s', + $backtrace[1]['class'], + $backtrace[1]['function'], + (isset($backtrace[1]['line']) ? $backtrace[1]['line'] : '0'), + $message + ); + } + // Try it: try { // Get debug instance @@ -1980,8 +1914,22 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * * @param $str The string with maybe dashes inside * @return $str The converted string with no dashed, but underscores - */ - public static final function convertDashesToUnderscores ($str) { + * @throws NullPointerException If $str is null + * @throws InvalidArgumentException If $str is empty + */ + public static function convertDashesToUnderscores ($str) { + // Is it null? + if (is_null($str)) { + // Throw NPE + throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER); + } elseif (!is_string($str)) { + // Entry is empty + throw new InvalidArgumentException(sprintf('str[]=%s is not a string', gettype($str)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY); + } elseif ((is_string($str)) && (empty($str))) { + // Entry is empty + throw new InvalidArgumentException('str is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); + } + // Convert them all $str = str_replace('-', '_', $str); @@ -3177,7 +3125,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ protected function initWebOutputInstance () { // Get application instance - $applicationInstance = Registry::getRegistry()->getInstance('app'); + $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); // Init web output instance $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class', array($applicationInstance)); @@ -3275,32 +3223,32 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * Creates a full-qualified file name (FQFN) for given file name by adding * a configured temporary file path to it. * - * @param $fileName Name for temporary file - * @return $fqfn Full-qualified file name + * @param $infoInstance An instance of a SplFileInfo class + * @return $tempInstance An instance of a SplFileInfo class (temporary file) * @throw PathWriteProtectedException If the path in 'temp_file_path' is write-protected * @throws FileIoException If the file cannot be written */ - protected static function createTempPathForFile ($fileName) { + protected static function createTempPathForFile (SplFileInfo $infoInstance) { // Get config entry - $basePath = FrameworkConfiguration::getSelfInstance()->getConfigEntry('temp_file_path'); + $basePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('temp_file_path'); // Is the path writeable? if (!is_writable($basePath)) { // Path is write-protected - throw new PathWriteProtectedException($fileName, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN); + throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN); } // END - if // Add it - $fqfn = $basePath . '/' . $fileName; + $tempInstance = new SplFileInfo($basePath . DIRECTORY_SEPARATOR . $infoInstance->getBasename()); // Is it reachable? - if (!FrameworkBootstrap::isReachableFilePath($fqfn)) { + if (!FrameworkBootstrap::isReachableFilePath($tempInstance)) { // Not reachable - throw new FileIoException($fqfn, self::EXCEPTION_FILE_NOT_REACHABLE); + throw new FileIoException($tempInstance, self::EXCEPTION_FILE_NOT_REACHABLE); } // END - if // Return it - return $fqfn; + return $tempInstance; } /**