[BUG] t3lib_div::getFilesInDir order differs from order in File list
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_div.php
index 173a5cd..77ac69c 100644 (file)
@@ -65,13 +65,6 @@ final class t3lib_div {
         */
        protected static $nonSingletonInstances = array();
 
-       /**
-        * Register for makeInstance with given class name and final class names to reduce number of class_exists() calls
-        *
-        * @var array Given class name => final class name
-        */
-       protected static $finalClassNameRegister = array();
-
        /*************************
         *
         * GET/POST Variables
@@ -513,7 +506,7 @@ final class t3lib_div {
                        $hex = self::normalizeIPv6($hex);
                                // Replace colon to nothing
                        $hex = str_replace(':', '', $hex);
-                       $bin = pack("H*", $hex);
+                       $bin = pack('H*', $hex);
                }
                return $bin;
        }
@@ -530,7 +523,7 @@ final class t3lib_div {
                if (defined('AF_INET6')) {
                        $hex = inet_ntop($bin);
                } else {
-                       $hex = unpack("H*", $bin);
+                       $hex = unpack('H*', $bin);
                        $hex = chunk_split($hex[1], 4, ':');
                                // Strip last colon (from chunk_split)
                        $hex = substr($hex, 0, -1);
@@ -1134,9 +1127,9 @@ final class t3lib_div {
         */
        public static function slashJS($string, $extended = FALSE, $char = "'") {
                if ($extended) {
-                       $string = str_replace("\\", "\\\\", $string);
+                       $string = str_replace('\\', '\\\\', $string);
                }
-               return str_replace($char, "\\" . $char, $string);
+               return str_replace($char, '\\' . $char, $string);
        }
 
        /**
@@ -2594,7 +2587,6 @@ final class t3lib_div {
                                }
                        }
                        $errno = 0;
-                               // $errstr = '';
                        $fp = @fsockopen($scheme . $parsedURL['host'], $port, $errno, $errstr, 2.0);
                        if (!$fp || $errno > 0) {
                                if (isset($report)) {
@@ -3006,7 +2998,7 @@ final class t3lib_div {
                                                                $sortarray[$key] = filemtime($path . '/' . $entry);
                                                        }
                                                        elseif ($order) {
-                                                               $sortarray[$key] = $entry;
+                                                               $sortarray[$key] = strtolower($entry);
                                                        }
                                                }
                                        }
@@ -3436,7 +3428,6 @@ final class t3lib_div {
                                        // $_SERVER['PATH_INFO']!=$_SERVER['SCRIPT_NAME'] is necessary because some servers (Windows/CGI) are seen to set PATH_INFO equal to script_name
                                        // Further, there must be at least one '/' in the path - else the PATH_INFO value does not make sense.
                                        // IF 'PATH_INFO' never works for our purpose in TYPO3 with CGI-servers, then 'PHP_SAPI=='cgi'' might be a better check. Right now strcmp($_SERVER['PATH_INFO'],t3lib_div::getIndpEnv('SCRIPT_NAME')) will always return FALSE for CGI-versions, but that is only as long as SCRIPT_NAME is set equal to PATH_INFO because of PHP_SAPI=='cgi' (see above)
-                                       //                              if (strcmp($_SERVER['PATH_INFO'],self::getIndpEnv('SCRIPT_NAME')) && count(explode('/',$_SERVER['PATH_INFO']))>1) {
                                if (PHP_SAPI != 'cgi' && PHP_SAPI != 'cgi-fcgi' && PHP_SAPI != 'fpm-fcgi') {
                                        $retVal = $_SERVER['PATH_INFO'];
                                }
@@ -3499,7 +3490,10 @@ final class t3lib_div {
                        case 'HTTP_ACCEPT_LANGUAGE':
                        case 'REMOTE_HOST':
                        case 'QUERY_STRING':
-                               $retVal = $_SERVER[$getEnvName];
+                               $retVal = '';
+                               if (isset($_SERVER[$getEnvName])) {
+                                       $retVal = $_SERVER[$getEnvName];
+                               }
                                break;
                        case 'TYPO3_DOCUMENT_ROOT':
                                        // Get the web root (it is not the root of the TYPO3 installation)
@@ -3644,7 +3638,9 @@ final class t3lib_div {
                } elseif (strpos($useragent, 'Flash') !== FALSE) {
                        $bInfo['BROWSER'] = 'flash';
                }
-               if ($bInfo['BROWSER']) {
+
+               $bInfo['FORMSTYLE'] = FALSE;
+               if (isset($bInfo['BROWSER'])) {
                                // Browser version
                        switch ($bInfo['BROWSER']) {
                                case 'net':
@@ -3680,9 +3676,10 @@ final class t3lib_div {
                        } elseif (strpos($useragent, 'Linux') !== FALSE || strpos($useragent, 'X11') !== FALSE || strpos($useragent, 'SGI') !== FALSE || strpos($useragent, ' SunOS ') !== FALSE || strpos($useragent, ' HP-UX ') !== FALSE) {
                                $bInfo['SYSTEM'] = 'unix';
                        }
+
+                               // Is TRUE if the browser supports css to format forms, especially the width
+                       $bInfo['FORMSTYLE'] = ($bInfo['BROWSER'] == 'msie' || ($bInfo['BROWSER'] == 'net' && $bInfo['VERSION'] >= 5) || $bInfo['BROWSER'] == 'opera' || $bInfo['BROWSER'] == 'konqu');
                }
-                       // Is TRUE if the browser supports css to format forms, especially the width
-               $bInfo['FORMSTYLE'] = ($bInfo['BROWSER'] == 'msie' || ($bInfo['BROWSER'] == 'net' && $bInfo['VERSION'] >= 5) || $bInfo['BROWSER'] == 'opera' || $bInfo['BROWSER'] == 'konqu');
 
                return $bInfo;
        }
@@ -3778,7 +3775,7 @@ final class t3lib_div {
         * So it's compatible with the UNIX style path strings valid for TYPO3 internally.
         *
         * @param string $theFile File path to evaluate
-        * @return boolean TRUE, $theFile is allowed path string
+        * @return boolean TRUE, $theFile is allowed path string, FALSE otherwise
         * @see http://php.net/manual/en/security.filesystem.nullbytes.php
         * @todo Possible improvement: Should it rawurldecode the string first to check if any of these characters is encoded?
         */
@@ -3786,6 +3783,8 @@ final class t3lib_div {
                if (strpos($theFile, '//') === FALSE && strpos($theFile, '\\') === FALSE && !preg_match('#(?:^\.\.|/\.\./|[[:cntrl:]])#u', $theFile)) {
                        return TRUE;
                }
+
+               return FALSE;
        }
 
        /**
@@ -3998,11 +3997,11 @@ final class t3lib_div {
         * @deprecated since TYPO3 4.7 - will be removed in TYPO3 4.9 - use t3lib_cacheHash instead
         */
        public static function cHashParams($addQueryParams) {
-               t3lib_div::logDeprecatedFunction();
+               self::logDeprecatedFunction();
                        // Splitting parameters up
                $params = explode('&', substr($addQueryParams, 1));
                /* @var $cacheHash t3lib_cacheHash */
-               $cacheHash = t3lib_div::makeInstance('t3lib_cacheHash');
+               $cacheHash = self::makeInstance('t3lib_cacheHash');
                $pA = $cacheHash->getRelevantParameters($addQueryParams);
 
                        // Hook: Allows to manipulate the parameters which are taken to build the chash:
@@ -4030,12 +4029,12 @@ final class t3lib_div {
         * @param string $addQueryParams Query-parameters: "&xxx=yyy&zzz=uuu"
         * @return string Hash of all the values
         * @see t3lib_div::cHashParams(), t3lib_div::calculateCHash()
-        * @deprecated since TYPO3 4.7 - will be removed in TYPO3 4.9 - use t3lib_cacheHash instead
+        * @deprecated since TYPO3 4.7 - will be removed in TYPO3 6.1 - use t3lib_cacheHash instead
         */
        public static function generateCHash($addQueryParams) {
-               t3lib_div::logDeprecatedFunction();
+               self::logDeprecatedFunction();
                /* @var $cacheHash t3lib_cacheHash */
-               $cacheHash = t3lib_div::makeInstance('t3lib_cacheHash');
+               $cacheHash = self::makeInstance('t3lib_cacheHash');
                return $cacheHash->generateForParameters($addQueryParams);
        }
 
@@ -4047,9 +4046,9 @@ final class t3lib_div {
         * @deprecated since TYPO3 4.7 - will be removed in TYPO3 4.9 - use t3lib_cacheHash instead
         */
        public static function calculateCHash($params) {
-               t3lib_div::logDeprecatedFunction();
+               self::logDeprecatedFunction();
                /* @var $cacheHash t3lib_cacheHash */
-               $cacheHash = t3lib_div::makeInstance('t3lib_cacheHash');
+               $cacheHash = self::makeInstance('t3lib_cacheHash');
                return $cacheHash->calculateCacheHash($params);
        }
 
@@ -4090,7 +4089,7 @@ final class t3lib_div {
         */
        public static function readLLfile($fileRef, $langKey, $charset = '', $errorMode = 0) {
                /** @var $languageFactory t3lib_l10n_Factory */
-               $languageFactory = t3lib_div::makeInstance('t3lib_l10n_Factory');
+               $languageFactory = self::makeInstance('t3lib_l10n_Factory');
                return $languageFactory->getParsedData($fileRef, $langKey, $charset, $errorMode);
        }
 
@@ -4118,7 +4117,10 @@ final class t3lib_div {
                        $validatedPrefix = PATH_typo3 . 'ext/';
                } elseif (self::isFirstPartOfStr($fileRef, PATH_typo3conf . 'ext/')) { // Is local:
                        $validatedPrefix = PATH_typo3conf . 'ext/';
-               } elseif (self::isFirstPartOfStr($fileRef, PATH_site . 'typo3_src/tests/')) { // Is test:
+               } elseif (self::isFirstPartOfStr($fileRef, PATH_site . 'tests/')) { // Is test:
+                       $validatedPrefix = PATH_site . 'tests/';
+                       $location = $validatedPrefix;
+               } elseif (self::isFirstPartOfStr($fileRef, PATH_site . 'typo3_src/tests/')) { // Is test (typo3_src deprecated as ov TYPO3 6.0):
                        $validatedPrefix = PATH_site . 'typo3_src/tests/';
                        $location = $validatedPrefix;
                } else {
@@ -4248,7 +4250,7 @@ final class t3lib_div {
 
        /**
         * Calls a user-defined function/method in class
-        * Such a function/method should look like this: "function proc(&$params, &$ref)        {...}"
+        * Such a function/method should look like this: "function proc(&$params, &$ref) {...}"
         *
         * @param string $funcName Function/Method reference, '[file-reference":"]["&"]class/function["->"method-name]'. You can prefix this reference with "[file-reference]:" and t3lib_div::getFileAbsFileName() will then be used to resolve the filename and subsequently include it by "require_once()" which means you don't have to worry about including the class file either! Example: "EXT:realurl/class.tx_realurl.php:&tx_realurl->encodeSpURL". Finally; you can prefix the class name with "&" if you want to reuse a former instance of the same object call ("singleton").
         * @param mixed $params Parameters to be pass along (typically an array) (REFERENCE!)
@@ -4291,7 +4293,7 @@ final class t3lib_div {
 
                        // Check prefix is valid:
                if ($checkPrefix && !self::hasValidClassPrefix($funcRef, array($checkPrefix))) {
-                       $errorMsg = "Function/class '$funcRef' was not prepended with '$checkPrefix'";
+                       $errorMsg = 'Function/class \'' . $funcRef . '\' was not prepended with \'' . $checkPrefix . '\'';
                        if ($errorMode == 2) {
                                throw new InvalidArgumentException($errorMsg, 1294585864);
                        } elseif (!$errorMode) {
@@ -4417,7 +4419,7 @@ final class t3lib_div {
                                return $classObj;
                        } else {
                                if (!$silent) {
-                                       debug("<strong>ERROR:</strong> No class named: " . $class, 't3lib_div::getUserObj');
+                                       debug('<strong>ERROR:</strong> No class named: ' . $class, 't3lib_div::getUserObj');
                                }
                        }
                }
@@ -4467,7 +4469,7 @@ final class t3lib_div {
                ) {
                        $validPrefixes = array_merge(
                                $validPrefixes,
-                               t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['additionalAllowedClassPrefixes'])
+                               self::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['additionalAllowedClassPrefixes'])
                        );
                }
                return $validPrefixes;
@@ -4490,12 +4492,7 @@ final class t3lib_div {
                        throw new InvalidArgumentException('$className must be a non empty string.', 1288965219);
                }
 
-                       // Determine final class name which must be instantiated, this takes XCLASS handling
-                       // into account. Cache in a local array to save some cycles for consecutive calls.
-               if (!isset(self::$finalClassNameRegister[$className])) {
-                       self::addClassNameToMakeInstanceCache($className, self::getClassName($className));
-               }
-               $finalClassName = self::$finalClassNameRegister[$className];
+               $finalClassName = self::getClassName($className);
 
                        // Return singleton instance if it is already registered
                if (isset(self::$singletonInstances[$finalClassName])) {
@@ -4567,22 +4564,6 @@ final class t3lib_div {
        }
 
        /**
-        * Adds a $className / $finalClassName to the cache register.
-        * This register is used to determine the final class name only once instead of multiple times.
-        *
-        * Warning: This is _not_ a public API method and must not be used in own extensions!
-        *
-        * @see makeInstance
-        * @param string $className the name of the class to set, must not be empty
-        * @param string $finalClassName the name of the final class which will be loaded in case of $className
-        * @return void
-        * @internal
-        */
-       public static function addClassNameToMakeInstanceCache($className, $finalClassName) {
-               self::$finalClassNameRegister[$className] = $finalClassName;
-       }
-
-       /**
         * Sets the instance of a non-singleton class to be returned by makeInstance.
         *
         * If this function is called multiple times for the same $className,
@@ -5086,7 +5067,7 @@ final class t3lib_div {
         *
         * @param string $msg Message (in English).
         * @param string $extKey Extension key (from which extension you are calling the log) or "Core"
-        * @param integer $severity Severity: 0 is info, 1 is notice, 2 is warning, 3 is error, 4 is fatal error
+        * @param integer $severity t3lib_div::SYSLOG_SEVERITY_* constant
         * @return void
         */
        public static function sysLog($msg, $extKey, $severity = 0) {
@@ -5133,7 +5114,7 @@ final class t3lib_div {
 
                                // Write message to a file
                        if ($type == 'file') {
-                               $lockObject = t3lib_div::makeInstance('t3lib_lock', $destination, $GLOBALS['TYPO3_CONF_VARS']['SYS']['lockingMode']);
+                               $lockObject = self::makeInstance('t3lib_lock', $destination, $GLOBALS['TYPO3_CONF_VARS']['SYS']['lockingMode']);
                                /** @var t3lib_lock $lockObject */
                                $lockObject->setEnableLogging(FALSE);
                                $lockObject->acquire();
@@ -5148,11 +5129,11 @@ final class t3lib_div {
                                // Send message per mail
                        elseif ($type == 'mail') {
                                list($to, $from) = explode('/', $destination);
-                               if (!t3lib_div::validEmail($from)) {
+                               if (!self::validEmail($from)) {
                                        $from = t3lib_utility_Mail::getSystemFrom();
                                }
                                /** @var $mail t3lib_mail_Message */
-                               $mail = t3lib_div::makeInstance('t3lib_mail_Message');
+                               $mail = self::makeInstance('t3lib_mail_Message');
                                $mail->setTo($to)
                                                ->setFrom($from)
                                                ->setSubject('Warning - error in TYPO3 installation')
@@ -5225,7 +5206,7 @@ final class t3lib_div {
                        }
                                // Write a longer message to the deprecation log
                        $destination = self::getDeprecationLogFileName();
-                       $lockObject = t3lib_div::makeInstance('t3lib_lock', $destination, $GLOBALS['TYPO3_CONF_VARS']['SYS']['lockingMode']);
+                       $lockObject = self::makeInstance('t3lib_lock', $destination, $GLOBALS['TYPO3_CONF_VARS']['SYS']['lockingMode']);
                        /** @var t3lib_lock $lockObject */
                        $lockObject->setEnableLogging(FALSE);
                        $lockObject->acquire();