/** * Load and cache the class map */ private static function loadClassMap() { if (self::$_classMapFileLocation && !self::$_noCache && self::loadClassMapFromCache()) { self::saveToApc(); return; } require_once __DIR__ . '/general/kLockBase.php'; $lock = kLockBase::grabLocalLock('KAutoloader'); // try loading again - some other instance may have created the cache while we waited for the lock if ($lock && self::loadClassMapFromCache()) { $lock->unlock(); return; } // cached map doesn't exists, rebuild the cache map if (self::$_classPath === null) { self::setDefaultClassPath(); } foreach (self::$_classPath as $dir) { if (strpos($dir, DIRECTORY_SEPARATOR . "*") == strlen($dir) - 2) { $dir = substr($dir, 0, strlen($dir) - 2); $recursive = true; } else { $recursive = false; } self::scanDirectory($dir, $recursive); } if (self::$_noCache === false && self::$_classMapFileLocation) { self::saveToApc(); $dirName = dirname(self::$_classMapFileLocation); if (!is_dir($dirName)) { mkdir($dirName); chmod($dirName, 0755); } // save the cached map $bytesWritten = self::safeFilePutContents(self::$_classMapFileLocation, serialize(self::$_classMap)); if (!$bytesWritten) { $folderPermission = substr(decoct(fileperms(dirname(self::$_classMapFileLocation))), 2); error_log("PHP Class map could not be saved to path [" . self::$_classMapFileLocation . "] folder permissions [{$folderPermission}]"); die("PHP Class map could not be saved"); } } if ($lock) { $lock->unlock(); } }