Writes YAML data to a file.

@param string $filename
The filename.
@param Data $data
The YAML file contents.

@return bool
TRUE if file was written successfully. Otherwise, FALSE.
179754
public function writeYamlFile($filename, $data)
    {
        try {
            // @todo Allow the inline and indent variables to be set via command line option.
            $yaml = Yaml::dump($data->export(), 3, 2);
        } catch (\Exception $e) {
            $this->output->writeln("<error>There was an error dumping the YAML contents for $filename.</error>");
            $this->output->writeln($e->getMessage());

            return false;
        }

        try {
            // @todo Use Symfony file system instead so that exceptions can be caught.
            file_put_contents($filename, $yaml);
        } catch (\Exception $e) {
            $this->output->writeln("<error>There was an writing to $filename.</error>");
            $this->output->writeln($e->getMessage());

            return false;
        }

        return true;
    }
831104
public static function write($file, $data, $lock = false) {
		return file_put_contents($file, $data, $lock ? LOCK_EX : 0);
	}
409938
public function save(string $filename, bool $debug = false): bool
    {
        $yaml = false;
        try {
            $fileObject = !$debug
                ? new \SplFileObject($filename, 'w')
                : new \SplTempFileObject();

            $yaml = Export::save($fileObject, $this->show());

        } catch (YamlException $e) {
            !$this->_strict ?: die();
        }

        return $yaml;
    }
102329
public static function save( $fileName, $data, $packetName = NULL )
	{
		if( $packetName === NULL )
			$wddx	= wddx_serialize_value( $data );
		else
			$wddx	= wddx_serialize_value( $data, $packetName );
		return FS_File_Writer::save( $fileName, $wddx );
	}
31490
protected function parseFileToData($fileName)
	{
		if (is_file($fileName))
		{
			$file = fopen($fileName,'r');
			flock($file,LOCK_SH);
			$this->data = parse_ini_file($fileName,true,INI_SCANNER_RAW);
			fclose($file);
			return true;
		}
		else
		{
			return false;
		}
	}
1041494
public function stream_write($data)
    {
        if ($this->fileHandle === null) {
            return false;
        }
        self::restore();
        $length = fwrite($this->fileHandle, $data);
        self::register();
        return $length;
    }
580394
public static function write($fileName, $data, $mode = 'w')
    {
        $json = json_encode($data, JSON_PRETTY_PRINT);

        if (json_last_error()) {
            throw new \RuntimeException(json_last_error_msg());
        }

        parent::write($fileName, $json, $mode);
    }
311792
public static function putContents(string $filename, $data, bool $override = false)
    {
        $dirname = dirname($filename);
        if (!file_exists($dirname)) {
            mkdir($dirname, 0700, true);
        }
        if (!file_exists($filename) || $override) {
            $result = file_put_contents($filename, $data);
        } else {
            throw new \Exception("{$filename} is already exists");
        }
        return $result;
    }
86387
protected static function saveJson( $fileName, $data )
	{
		$json	= array();
		foreach( $data as $sectionName => $sectionData )
		{
			foreach( $sectionData as $pair )
			{
				$key	= $pair['key'];
				unset( $pair['key'] );
				$json[$sectionName][$key]	= $pair;
			}
		}
		$json	= ADT_JSON_Formater::format( $json, TRUE );
		return FS_File_Writer::save( $fileName, $json );
	}
117573
static public function save(object $fileObject, string $data)
    {
        $write = $fileObject->fwrite($data);
        YamlException::export($write);
        return $write;
    }
791749
public static function write($filename, $data, $permission = 0777, $flags = LOCK_EX, $relative = true) {
		// if we have relative path we convert it to full path
		if ($relative && $filename[0] == '.') {
			$path = \Application::get('application.path_full');
			$info = pathinfo($filename);
			$filename = realpath($path . $info['dirname']) . DIRECTORY_SEPARATOR . $info['basename'];
		}
		// write file
		if (file_put_contents($filename, $data, $flags) !== false) {
			@chmod($filename, $permission);
			return true;
		}
		return false;
	}
922107
public function render($filename, array $data = [])
    {
        $filename = $this->checkParseFile($filename, false);

        return $this->template->render($filename, $data);
    }
913455
public function create($fileName, $data)
    {
        $path = $this->getPathBase($fileName);

        if (file_exists($path)) {
            return;
        }

        $data = serialize($data);

        return file_put_contents($path, $data);
    }
1352584
public function save($data)
	{
		if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
		{
			if ($data instanceof SimplePie)
			{
				$data = $data->data;
			}

			$data = serialize($data);
			return (bool) file_put_contents($this->name, $data);
		}
		return false;
	}
1217064
private function write( string $file, $data, $append ): bool
	{
		if( function_exists('error_clear_last') )
		{
			error_clear_last();
		}

		// check directory exists or create empty directory for file
		$path = dirname($file);
		if( ! is_dir($path) )
		{
			try
			{
				if( ! @ mkdir($path, 0755, true) ) throw new WriteException("Cannot create the '{$path}' directory");
			}
			catch( \ErrorException $e )
			{
				return $this->getError($e);
			}
		}

		// check directory is writable
		if( ! is_writable($path) )
		{
			return $this->getError(new WriteFileException($file));
		}

		// detect write mode
		// ignore append flag if file is not exists
		$mode = "wa+";
		if( $append )
		{
			if( file_exists( $file ) )
			{
				$mode = "w";
			}
			else
			{
				$append = false;
			}
		}

		try {
			$handle = @ fopen( $file, $mode );
			if( ! $handle )
			{
				throw new WriteFileException($file,"Cannot open the '{$file}' file for write");
			}

			$callable = $data instanceof \Closure;
			if( flock( $handle, LOCK_EX ) )
			{
				if( $callable )
				{
					do
					{
						$content = $data( $append );
						if( ! is_string($content) || strlen($content) < 1 )
						{
							break;
						}
						if( fwrite( $handle, $content ) === false )
						{
							throw new WriteFileException($file);
						}
					}
					while(true);
				}
				else if( fwrite( $handle, $data ) === false )
				{
					throw new WriteFileException($file);
				}

				fflush( $handle );
				flock(  $handle, LOCK_UN );
			}
			else
			{
				throw new WriteFileException($file);
			}
		}
		catch( \ErrorException $e )
		{
			if( isset($handle) && ! $append && file_exists($file) )
			{
				@ unlink($file);
			}
			return $this->getError($e);
		}
		finally
		{
			if( isset($handle) )
			{
				fclose($handle);
			}
		}

		if( $this instanceof Loggable )
		{
			$this->addLogDebug("The '{$file}' file is successfully " . ($append ? "updated" : "created"));
		}

		return true;
	}
992649
public static function php($data, $fileName) {
        $filePath = Config::getx('path_temp') . $fileName.'.php';
        $result = file_put_contents($filePath, "<?php\nreturn " . var_export($data, true) . ";");
        return $result;
    }
1353527
public function excel($filename, $data)
    {
        \Excel::create($filename, function ($excel) use ($filename, $data) {
            $excel->sheet($filename, function ($sheet) use ($data) {
                $sheet->fromArray($data);
            });
        })
              ->export('xlsx');
    }