Record server runtime info.

@param string $filename
184182
protected function saveRuntime($filename)
    {
        $payload = [
            'name' => $this->laravel->name(),
            'pid'  => getmypid(),
            'time' => (string) Carbon::now(),
        ];

        file_put_contents($filename, json_encode($payload, JSON_PRETTY_PRINT));
    }
280697
protected function load($filename)
    {
        $this->catalog = array();

        $fp = fopen($filename, 'rb', false);
        if ($fp === false) {
            throw new \RuntimeException("Could not read $filename");
        }

        $data = fread($fp, 20);
        if (strlen($data) != 20) {
            throw new \RuntimeException('Invalid file');
        }

        $magic = substr($data, 0, 4);
        if ($magic === "\x95\x04\x12\xde") {
            $dword = 'N';
        } elseif ($magic === "\xde\x12\x04\x95") {
            $dword = 'V';
        } else {
            throw new \RuntimeException('Invalid file');
        }

        list(, $revision) = unpack("@4/${dword}", $data);

        if ($revision !== 0) {
            throw new \RuntimeException('Invalid file');
        }

        list(, $count, $origOffset, $transOffset) = unpack("@8/${dword}3", $data);

        fseek($fp, $origOffset);
        $origEntries = array();
        for ($i = 0; $i < $count; $i++) {
            $origEntries[] = unpack("${dword}2", fread($fp, 8));
        }

        fseek($fp, $transOffset);
        $transEntries = array();
        for ($i = 0; $i < $count; $i++) {
            $transEntries[] = unpack("${dword}2", fread($fp, 8));
        }

        for ($i = 0; $i < $count; $i++) {
            fseek($fp, $origEntries[$i][2]);
            $msgid = $origEntries[$i][1] > 0 ? fread($fp, $origEntries[$i][1]) : "";
            fseek($fp, $transEntries[$i][2]);
            $translations = $transEntries[$i][1] > 0 ? explode("\x00", fread($fp, $transEntries[$i][1])) : "";

            $ctx = self::NO_CONTEXT;
            if (($pos = strpos($msgid, self::NO_CONTEXT)) !== false) {
                $ctx = (string) substr($msgid, 0, $pos);
                $msgid = (string) substr($msgid, $pos + 1);
            }

            $this->catalog[$ctx][$msgid] = $translations;
        }
    }
383375
private function readFile($fileName) {
        try {
            $data = file_get_contents($fileName, false);
        }
        catch (PHPError $ex) {
            if (strEndsWith($ex->getMessage(), 'failed to open stream: No such file or directory'))
                return null;
            throw $ex;
        }

        if ($data === false)
            throw new RuntimeException('file_get_contents() returned FALSE, $fileName: "'.$fileName);

        return unserialize($data);
    }
1126251
public static function clearStatCache($filename = null) {
    if (!empty($filename)) {
      unset(self::$stat_cache[self::getHashValue($filename)]);
    } else {
      self::$stat_cache = [];
    }
  }
280287
private function handleHackFile($fileName)
    {
        $logger   = $this->logger;
        $previous = spl_autoload_functions();

        include $fileName;

        $found = $this->determineRegisteredAutoLoader($previous);

        foreach ($found as $index => $loader) {
            $hackName = basename($fileName) . '.' . $index;
            $this->enumLoader->add($this->compileHack($loader, $hackName), $hackName);
        }
        $logger->debug(
            'Custom class loader hack {file} loaded {count} auto load functions.',
            array('file' => $fileName, 'count' => count($found))
        );
    }
6557
public static function load(string $filename) {
		if(class_exists(Dotenv::class)) {
			$dotenv = new Dotenv($filename);
			$dotenv->load();
		}
	}
766700
public static function checkAndLoad(string $filename): string
    {
        $includePathFilename = \stream_resolve_include_path($filename);

        // As a fallback, PHP looks in the directory of the file executing the stream_resolve_include_path function.
        // We don't want to load the Test.php file here, so skip it if it found that.
        // PHP prioritizes the include_path setting, so if the current directory is in there, it will first look in the
        // current working directory.
        $localFile = __DIR__ . DIRECTORY_SEPARATOR . $filename;

        $isReadable = @\fopen($includePathFilename, 'r') !== false;

        if (!$includePathFilename || !$isReadable || $includePathFilename === $localFile) {
            throw new \Exception(\sprintf('Cannot open file "%s".' . "\n", $filename));
        }

        require_once $includePathFilename;

        return $includePathFilename;
    }
853445
public function deleteFile($fileName) {
        $files = $this->getFiles();
        $success = false;
        foreach ($files as $file) {
            if($file->getRelativePathname() === $fileName){
                if(!$file->isWritable()){
                    throw new RuntimeException(sprintf("The file '%s' is not writable and can not be deleted.",$fileName));
                }
                unlink($file->getRealPath());
                if($file->isReadable()){
                    throw new RuntimeException(sprintf("The file '%s' could not be deleted",$fileName));
                }
                $success = true;
            }
        }
        return $success;
    }
785671
protected function recordMethodInvocation($methodName)
    {
        if ($this->in_static_mode) {
            $this->expectedStaticMethodCalls[] = $methodName;
        } else {
            $this->expectedInstanceMethodCalls[] = $methodName;
        }
    }
559216
public static function read($fileName)
    {
        if (!file_exists($fileName)) {
            throw new RuntimeException($fileName.' not exist');
        }
        if (!is_readable($fileName)) {
            throw new RuntimeException($fileName.' not readable');
        }

        $fh = fopen($fileName, "r");
        $data = fread($fh, filesize($fileName));
        fclose($fh);

        return $data;
    }
722806
public function toFile($filename)
    {
        $directory = dirname($filename);

        if(empty($filename)) {
            throw new \InvalidArgumentException('No file name specified');
        }

        if (!is_dir($directory)) {
            throw new \RuntimeException(sprintf('Directory : %s does not exists!', $directory));
        }

        if (!is_writable($directory)) {
            throw new \RuntimeException(sprintf("Cannot write in directory : %s", $directory));
        }

        $result = file_put_contents($filename, $this->toString(), LOCK_EX);

        if($result === false) {
            throw new \RuntimeException(sprintf("Error writing to %s", $filename));
        }
    }
455691
public static function load(string $filename) {
		$data = parse_ini_file($filename, true);
		if (!empty($data['registry'])) {
			foreach ($data['registry'] as $k => $v) {
				array_key_set(self::$settings, explode('.', $k), $v);
			}
		}
	}
246660
public function open($filename)
    {
        $pathInfo = pathinfo($filename);
        if (!key_exists('extension', $pathInfo) || !in_array($pathInfo['extension'], $this->settings->getExtraFiletypes())) {
            parent::open($filename);
        }
    }
632168
private function prepareFilename($filename)
    {
        $this->filename = $filename;

        if (!$this->filename) {
            $this->filename = $this->content->getMetadata('uri');
        }

        if (!$this->filename || substr($this->filename, 0, 6) === 'php://') {
            $this->filename = $this->name;
        }
    }
649596
public function setFileName($fileName)
	{
		$hasFilename = ($this->fileName !== null);
		
		if ($hasFilename) {
			$previousName = $this->fileName;
			$previousExtension = $this->getExtension();
		}
		
		parent::setFileName($fileName);
		
		if ($hasFilename) {
			
			$newExtension = $this->getExtension();

			if (strcasecmp($previousExtension, $newExtension) !== 0) {

				// restore name back to previous one. Because that's safer.
				parent::setFileName($previousName);

				throw new \RuntimeException('Extension change is not allowed');
			}
		}
	}
628971
static private function ensureDirExists($filename) {
		$logdir= dirname($filename);
		if(!file_exists($logdir)) {
			mkdir($logdir, 0775, true);
			chmod($logdir, 0775);
		}
		
		// check if writeable and if not, write a hint in Objectcache
		$cache = \ObjectCache::getInstance(CACHE_DB);
		$cache->delete('DIQA.Util.logFileNotWriteable');
		@touch($filename);
		if (!is_writeable($filename)) {
			global $wgDIQAUtilLogDir;
			$cache->set('DIQA.Util.logFileNotWriteable', $wgDIQAUtilLogDir);
		}
	}
232884
public static function loadRuntimeInfo($fileName)
    {
        if(!is_file($fileName))
        {
            return false;
        }
        static::$runtimeInfo = unserialize(file_get_contents($fileName));
        $data = static::$runtimeInfo->annotationParserData;
        Annotation::getInstance()->getParser()->setData($data[0]);
        Annotation::getInstance()->getParser()->setFileMap($data[1]);
        Annotation::getInstance()->getParser()->setParsers(static::$runtimeInfo->annotationParserParsers);
        AnnotationManager::setAnnotations(static::$runtimeInfo->annotationManagerAnnotations);
        AnnotationManager::setAnnotationRelation(static::$runtimeInfo->annotationManagerAnnotationRelation);
        foreach(static::$runtimeInfo->parsersData as $parserClass => $data)
        {
            $parser = $parserClass::getInstance();
            $parser->setData($data);
        }
        return true;
    }