X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Fclass_BaseFrameworkSystem.php;h=721e4ec52556f44fd7924358be9a83ba200167ee;hp=9262934f375aa10fc3c04c7d5473ec746a03f0d6;hb=63f5632b0c5d2cebf8dd0940fdab561f86470f80;hpb=c0cd963d2909edf773bfef702df042822a31f946 diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index 9262934f..721e4ec5 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -14,6 +14,7 @@ use CoreFramework\Criteria\Local\LocalUpdateCriteria; use CoreFramework\Crypto\Cryptable; use CoreFramework\Crypto\RandomNumber\RandomNumberGenerator; use CoreFramework\Database\Frontend\DatabaseWrapper; +use CoreFramework\EntryPoint\ApplicationEntryPoint; use CoreFramework\Factory\Database\Wrapper\DatabaseWrapperFactory; use CoreFramework\Factory\ObjectFactory; use CoreFramework\Filesystem\Block; @@ -23,7 +24,9 @@ use CoreFramework\Filesystem\PathWriteProtectedException; use CoreFramework\Generic\FrameworkInterface; use CoreFramework\Generic\NullPointerException; use CoreFramework\Generic\UnsupportedOperationException; +use CoreFramework\Handler\Handleable; use CoreFramework\Handler\Stream\IoHandler; +use CoreFramework\Helper\Helper; use CoreFramework\Index\Indexable; use CoreFramework\Lists\Listable; use CoreFramework\Loader\ClassLoader; @@ -38,15 +41,19 @@ use CoreFramework\Result\Database\CachedDatabaseResult; use CoreFramework\Result\Search\SearchableResult; use CoreFramework\Stacker\Stackable; use CoreFramework\State\Stateable; +use CoreFramework\Stream\Input\InputStream; use CoreFramework\Stream\Output\OutputStreamer; +use CoreFramework\Stream\Output\OutputStream; use CoreFramework\Template\CompileableTemplate; use CoreFramework\User\ManageableAccount; use CoreFramework\Visitor\Visitor; // Import SPL stuff use \stdClass; +use \InvalidArgumentException; use \Iterator; use \ReflectionClass; +use \SplFileInfo; /** * The simulator system class is the super class of all other classes. This @@ -167,11 +174,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $parserInstance = NULL; - /** - * A HandleableProtocol instance - */ - private $protocolInstance = NULL; - /** * A database wrapper instance */ @@ -203,7 +205,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { private $outputStreamInstance = NULL; /** - * Networkable handler instance + * Handler instance */ private $handlerInstance = NULL; @@ -212,11 +214,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $visitorInstance = NULL; - /** - * DHT instance - */ - private $dhtInstance = NULL; - /** * An instance of a database wrapper class */ @@ -262,6 +259,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 */ @@ -302,11 +309,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 @@ -401,6 +403,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { const EXCEPTION_PATH_CANNOT_BE_WRITTEN = 0x03b; const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x03c; const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03d; + const EXCEPTION_INVALID_SOCKET = 0x03e; /** * Hexadecimal->Decimal translation array @@ -464,7 +467,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) @@ -492,8 +495,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { $this->setRealClass('DestructedObject'); } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) { // Already destructed object - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:] The object %s is already destroyed.', - __CLASS__, + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('The object %s is already destroyed.', $this->__toString() )); } else { @@ -585,7 +587,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Output stub message // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[unknown::%s:] Stub! Args: %s', + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[unknown::%s]: Stub! Args: %s', $methodName, $argsString )); @@ -1136,25 +1138,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 * @@ -1324,7 +1307,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { /** * Getter for handler instance * - * @return $handlerInstance A Networkable instance + * @return $handlerInstance A Handleable instance */ protected final function getHandlerInstance () { return $this->handlerInstance; @@ -1349,25 +1332,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 * @@ -1575,6 +1539,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 * @@ -1613,25 +1615,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 @@ -1753,7 +1736,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 @@ -1766,7 +1751,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() @@ -1799,19 +1793,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)) { @@ -1871,7 +1854,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // 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)); @@ -1880,11 +1863,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 + Registry::getRegistry()->addInstance('debug', $debugInstance); } else { // Get instance from registry - $debugInstance = Registry::getRegistry()->getDebugInstance(); + $debugInstance = Registry::getRegistry()->getInstance('debug'); } // Return it @@ -1916,6 +1899,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 @@ -1979,8 +1984,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); @@ -2578,20 +2597,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { return $ret; } - /** - * Checks whether start/end marker are set - * - * @param $data Data to be checked - * @return $isset Whether start/end marker are set - */ - public final function ifStartEndMarkersSet ($data) { - // Determine it - $isset = ((substr($data, 0, strlen(BaseRawDataHandler::STREAM_START_MARKER)) == BaseRawDataHandler::STREAM_START_MARKER) && (substr($data, -1 * strlen(BaseRawDataHandler::STREAM_END_MARKER), strlen(BaseRawDataHandler::STREAM_END_MARKER)) == BaseRawDataHandler::STREAM_END_MARKER)); - - // ... and return it - return $isset; - } - /** * Determines if an element is set in the generic array * @@ -3288,32 +3293,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; } /**