Write to a file, and throw a RuntimeException if it cannot be done.

@param string $filename The path to the file
@param string $contents The data to write to the file

@return void
331191
public static function putContents($filename, $contents)
    {
        $result = file_put_contents($filename, $contents, \LOCK_EX | \LOCK_NB);
        if ($result === false) {
            throw new \RuntimeException("Cannot write the file: " . $filename);
        }
    }
882536
private function _writeToFile($filename, $contents)
    {
        // Check local tmp directory
        if (!is_dir($this->config['tmp']) || !is_writeable($this->config['tmp'])) {
            $this->fail('tmp directory not found or is not writable');
        }

        // Build temp file
        $tmp_file = $this->config['tmp'] . "/ftp_data_file.tmp";
        file_put_contents($tmp_file, $contents);

        // Update variables
        $this->filepath = $filename;
        $this->file = $contents;

        // Upload the file to server
        if ($this->isSFTP()) {
            $flag = defined('NET_SFTP_LOCAL_FILE') ? NET_SFTP_LOCAL_FILE : \phpseclib\Net\SFTP::SOURCE_LOCAL_FILE;

            $uploaded = @$this->ftp->put($filename, $tmp_file, $flag);
        } else {
            $uploaded = ftp_put($this->ftp, $filename, $tmp_file, FTP_BINARY);
        }
        if (!$uploaded) {
            $this->fail('failed to upload file to server');
        }
    }
316279
protected function saveFile($filename, $content)
	{
		$filename = $this->dir . $filename; 
		$f = fopen($filename, "wb");
		if($f)
		{
			if(fwrite($f, $this->processForFile($content)))
			{
				fclose($f);
				chmod($filename, 0600);
				return true;
			}
			fclose($f);
		}
		return false;
	}
556401
public function appendToFile($filename, $content)
    {
        if (\is_array($content)) {
            @trigger_error(sprintf('Calling "%s()" with an array in the $content argument is deprecated since Symfony 4.3.', __METHOD__), E_USER_DEPRECATED);
        }

        $dir = \dirname($filename);

        if (!is_dir($dir)) {
            $this->mkdir($dir);
        }

        if (!is_writable($dir)) {
            throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
        }

        if (false === @file_put_contents($filename, $content, FILE_APPEND)) {
            throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
        }
    }
487521
public function write(AssetTarget $build, $content)
    {
        $ext = $build->ext();
        $path = $build->outputDir();

        if (!is_writable($path)) {
            throw new RuntimeException('Cannot write cache file. Unable to write to ' . $path);
        }
        $filename = $this->buildFileName($build);
        $success = file_put_contents($path . DIRECTORY_SEPARATOR . $filename, $content) !== false;
        $this->finalize($build);
        return $success;
    }
136161
public function save($data): void
    {
        if (\is_string($data)) {
            // Make sure that the string is valid data.
            try {
                $this->formatter->decode($data);
            } catch (RuntimeException $e) {
                throw new RuntimeException(sprintf("Failed to save file '%s': %s", $this->getFilePath(), $e->getMessage()), $e->getCode(), $e);
            }
            $encoded = $data;
        } else {
            $encoded = $this->formatter->encode($data);
        }

        parent::save($encoded);
    }
557210
protected function writeFile($filePath, $content)
    {
        $this->validateOutputDirectoryPermissions();

        $currentDirectory = dirname($filePath);
        if (!is_writable($currentDirectory)) {
            throw new \OxidEsales\UnifiedNameSpaceGenerator\Exceptions\PermissionException(
                'Could not create file ' . $filePath . ' ' .
                'The directory ' . $currentDirectory . ' is not writable for user "' . get_current_user() . '". ' .
                'Please fix the permissions on this directory and run this script again.',
                static::ERROR_CODE_FILE_CREATION_ERROR
            );
        }

        $fileHandle = fopen($filePath, 'wb');
        if (!$fileHandle) {
            throw new \OxidEsales\UnifiedNameSpaceGenerator\Exceptions\FileSystemCompatibilityException(
                'Could not open file file handle for ' . $filePath . ' ' .
                'There might be a problem with your file system. Try to solve this problem and run this script again.',
                static::ERROR_CODE_FILE_CREATION_ERROR
            );
        }

        $result = fwrite($fileHandle, $content);
        if (false === $result) {
            fclose($fileHandle);
            throw new \Exception(
                'Could not create file ' . $filePath,
                static::ERROR_CODE_FILE_CREATION_ERROR
            );
        }
        if (0 === $result) {
            fclose($fileHandle);
            throw new \Exception(
                'Created empty file ' . $filePath,
                static::ERROR_CODE_FILE_CREATION_ERROR
            );
        }
        fclose($fileHandle);
    }
1237044
protected function set_data(array $contents = [])
    {
        foreach ($contents as $key => $file) {
            $this->data[ $key ] = $this->add_file($file);
        }
    }
1370843
public function writeFile(string $filename, string $data, int $mode = null) : void
    {
        if ($mode === null) {
            $mode = 0600;
        }
        /** @psalm-suppress UndefinedClass */
        System::writeFile($filename, $data, $mode);
    }
360342
public function save($filename, $content) {
        if ($this->driver) {
            return $this->driver->save($filename, $content);
        }

        return false;
    }
816556
public function writeFile(
        string $content,
        string $filename,
        string $encoding = Encoder::DEFAULT_BYTE_MODE_ECODING,
        ?ErrorCorrectionLevel $ecLevel = null
    ) : void {
        file_put_contents($filename, $this->writeString($content, $encoding, $ecLevel));
    }
306429
public function write($contents, $filename, $directory)
    {
        $path = rtrim($directory, '/') . '/' . $filename . '.php';

        if (!file_exists($directory)) {
            throw new InvalidArgumentException(sprintf('Migrations directory "%s" does not exist.', $directory));
        }

        return file_put_contents($path, $contents);
    }
1241857
public function write($configuration)
    {
        $ht = $this->getHTaccessFilename();
        $fs = $this->getFilesystem();
        if (@$fs->put($ht, $configuration) === false) {
            throw new Exception("Failed to write to file $ht");
        }
    }
933424
private function saveContent($file, $content)
    {
        if (file_put_contents($file, $content, LOCK_EX) === false) {
            throw new RuntimeException('Plugin Manager is not able to save ' . $file . '.'); // @codeCoverageIgnore
        }
    }
1352773
public function write($file)
    {
        if (file_exists($file) && !is_writable($file)) {
            throw new RuntimeException("$file is not writable");
        }
        $fp = fopen($file, 'w');
        foreach ($this->lines as $line) {
            fwrite($fp, $line['data']);
        }
        fclose($fp);
    }
379771
public static function write($filename, $content, $mode = 0666)
    {
        self::ensureFileSystem()->dumpFile($filename, $content, $mode);
    }
797325
private function write($src, $fileName, $content)
    {

        if (!$this->file->exists($src)) {
            $this->file->makeDirectory($src);
        }
        $this->file->put($fileName, $content);
    }