X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fclass_BaseFrameworkSystem.php;h=d76b3d2ec40d4ff71a5f7e9c1809095b315ced3c;hp=3f3e6f7a779e7d06882c5871cfb3e24c5fcded7e;hb=0ccdb0379f308c6b7b5677b8b7c242df8e9dd300;hpb=be65e8b394b142696c4a72b5945cd2a3e6d3585c diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 3f3e6f7a..d76b3d2e 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -213,6 +213,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $listenerInstance = NULL; + /** + * An instance of a communicator + */ + private $communicatorInstance = NULL; + /** * Thousands separator */ @@ -341,9 +346,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { const EXCEPTION_FATAL_ERROR = 0x035; const EXCEPTION_FILE_NOT_FOUND = 0x036; const EXCEPTION_ASSERTION_FAILED = 0x037; - const EXCEPTION_FILE_CANNOT_BE_READ = 0x038; - const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039; - const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03a; + const EXCEPTION_FILE_NOT_REACHABLE = 0x038; + const EXCEPTION_FILE_CANNOT_BE_READ = 0x039; + const EXCEPTION_FILE_CANNOT_BE_WRITTEN = 0x03a; + const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x03b; + const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x03c; /** * Hexadecimal->Decimal translation array @@ -468,10 +475,13 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Init argument string $argsString = ''; - // Is it empty or an array? - if (empty($args)) { + // Is it NULL, empty or an array? + if (is_null($args)) { // No arguments $argsString = 'NULL'; + } elseif (empty($args)) { + // Empty arguments + $argsString = '(empty)'; } elseif (is_array($args)) { // Some arguments are there foreach ($args as $arg) { @@ -1504,6 +1514,25 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { return $this->listenerInstance; } + /** + * 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 command name * @@ -1865,12 +1894,12 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @param $str The string, what ever it is needs to be converted * @return $className Generated class name */ - public function convertToClassName ($str) { + public static final function convertToClassName ($str) { // Init class name $className = ''; // Convert all dashes in underscores - $str = $this->convertDashesToUnderscores($str); + $str = self::convertDashesToUnderscores($str); // Now use that underscores to get classname parts for hungarian style foreach (explode('_', $str) as $strPart) { @@ -1888,7 +1917,7 @@ 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 final function convertDashesToUnderscores ($str) { + public static final function convertDashesToUnderscores ($str) { // Convert them all $str = str_replace('-', '_', $str); @@ -2058,7 +2087,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($fieldName.':
'.print_r($fieldArray, TRUE).'
'); // Convert dashes to underscore - $fieldName2 = $this->convertDashesToUnderscores($fieldName); + $fieldName2 = self::convertDashesToUnderscores($fieldName); // Does the field exist? if ($this->isFieldSet($fieldName)) { @@ -2098,7 +2127,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . $this->__toString() . ':' . __LINE__ . '] fieldName=' . $fieldName . ',fieldArray=
'.print_r($fieldArray, TRUE).'
'); // Convert dashes to underscore - $fieldName = $this->convertDashesToUnderscores($fieldName); + $fieldName = self::convertDashesToUnderscores($fieldName); // Determine it $isSet = isset($fieldArray[$fieldName]); @@ -3201,6 +3230,58 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__)->debugOutput('packed=' . $packed . ' - EXIT!'); return $packed; } + + /** + * Checks whether the given file/path is in open_basedir(). This does not + * gurantee that the file is actually readable and/or writeable. If you need + * such gurantee then please use isReadableFile() instead. + * + * @param $filePathName Name of the file/path to be checked + * @return $isReachable Whether it is within open_basedir() + */ + public static function isReachableFilePath ($filePathName) { + // Is not reachable by default + $isReachable = FALSE; + + // Get open_basedir parameter + $openBaseDir = ini_get('open_basedir'); + + // Is it set? + if (!empty($openBaseDir)) { + // Check all entries + foreach (explode(PATH_SEPARATOR, $openBaseDir) as $dir) { + // Check on existence + if (substr($filePathName, 0, strlen($dir)) == $dir) { + // Is reachable + $isReachable = TRUE; + } // END - if + } // END - foreach + } else { + // If open_basedir is not set, all is allowed + $isReachable = TRUE; + } + + // Return status + return $isReachable; + } + + /** + * Checks whether the give file is within open_basedir() (done by + * isReachableFilePath()), is actually a file and is readable. + * + * @param $fileName Name of the file to be checked + * @return $isReadable Whether the file is readable (and therefor exists) + */ + public static function isReadableFile ($fileName) { + // Default is not readable + $isReadable = FALSE; + + // Is within parameters, so check if it is a file and readable + $isReadable = ((self::isReachableFilePath($fileName)) && (file_exists($fileName)) && (is_file($fileName)) && (is_readable($fileName))); + + // Return status + return $isReadable; + } } // [EOF]