IniFile::writeFile

@param string $filePath Path to the file.
@param array  $options  Write file options.

@return bool Returns TRUE on success or FALSE on failure.
432612
public function writeFile($filePath = null, array $options = [])
    {
        $filePath = empty($filePath)
            ? $this->filePath
            : $filePath;

        $sections = (empty($options)
            ? true
            : $options[ 'sections' ]);

        $content = null;

        if ($sections) {
            foreach ($this->getArrayCopy() as $section => $data) {
                if (is_array($data)) {
                    $content .= '[' . $section . ']' . PHP_EOL;

                    foreach ($data as $key => $value) {
                        if (is_array($value)) {
                            foreach ($value as $valueChild) {
                                $content .= $key . '[] = ' . (is_numeric($valueChild)
                                        ? $valueChild
                                        : '"' . $valueChild . '"') . PHP_EOL;
                            }
                        } elseif (strpos($key, ';') !== false) {
                            $content .= '; ' . trim(ucfirst($key), ';') . ' ' . $value . PHP_EOL;
                        } elseif (empty($value)) {
                            $content .= $key . ' = ' . PHP_EOL;
                        } else {
                            $content .= $key . ' = ' . (is_numeric($value)
                                    ? $value
                                    : '"' . $value . '"') . PHP_EOL;
                        }
                    }

                    $content .= PHP_EOL;
                } elseif (strpos($section, ';') !== false) {
                    $content .= '; ' . trim(ucfirst($section), ';') . ' ' . $data . PHP_EOL;
                } elseif (empty($data)) {
                    $content .= $section . ' = ' . PHP_EOL;
                } else {
                    $content .= $section . ' = ' . (is_numeric($data)
                            ? $data
                            : '"' . $data . '"') . PHP_EOL;
                }
            }
        } else {
            foreach ($this->getArrayCopy() as $key => $value) {
                if (is_array($value)) {
                    foreach ($value as $valueChild) {
                        $content .= $key . '[] = ' . (is_numeric($valueChild)
                                ? $valueChild
                                : '"' . $valueChild . '"') . PHP_EOL;
                    }
                } elseif (strpos($key, ';') !== false) {
                    $content .= '; ' . trim(ucfirst($key), ';') . ' ' . $value . PHP_EOL;
                } elseif (empty($value)) {
                    $content .= $key . ' = ' . PHP_EOL;
                } else {
                    $content .= $key . ' = ' . (is_numeric($value)
                            ? $value
                            : '"' . $value . '"') . PHP_EOL;
                }
            }
        }

        return (new File())->write($filePath, $content);
    }
303047
public function createWriter($filePath, $delimiter = WriterInterface::DELIMITER_DEFAULT, $fileCharset = WriterInterface::CHARSET_DEFAULT, $mode = 'w', $type = null)
    {
        if (null === $type) {
            $type = $this->getDefaultWriterType();
        }

        return $this->getWriterFactory()->createWriter($type, $filePath, $delimiter, $fileCharset, $mode);
    }
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);
    }
221956
public function readFile($filePath = null, array $options = [])
    {
        $filePath = empty($filePath)
            ? $this->filePath
            : $filePath;

        $result = new ArrayIterator();

        if (false !== ($contents = json_decode(file_get_contents($filePath), true))) {
            if (json_last_error() === JSON_ERROR_NONE) {
                foreach ($contents as $content) {
                    $result[] = new SplArrayObject($content);
                }
            }
        }

        return $result;
    }
530343
public function setOutput($filepath = 'stdout')
  {
    if ($filepath != 'stdout' && !($filepath instanceof OutputInterface) && !file_exists(dirname($filepath))) {
      throw new \InvalidArgumentException("Cannot write to $filepath. Parent directory doesn't exist.");
    }
    $this->output = $filepath;
    return $this;
  }
1199991
protected function init($filepath)
    {
        $this->file = new \SplFileObject($filepath);

        if (!$this->file->isFile()) {
            throw new \LogicException('This is not a file', 1);
        }

        if (!$this->file->isReadable()) {
            throw new \Exception('This file is not readable', 1);
        }

        if (!$this->file->isWritable()) {
            //throw new \Exception("This file is not writable", 1);
        }

        $this->filepath = $this->file->getPathName();
    }
57668
public function readFile($filePath = null, array $options = [])
    {
        $filePath = empty($filePath)
            ? $this->filePath
            : $filePath;


        $result = [];

        if (extension_loaded('zip')) {
            if ($zipHandle = zip_open($filePath)) {
                while ($zipContent = zip_read($zipHandle)) {
                    $result[] = zip_entry_name($zipContent);
                }

                zip_close($zipHandle);
            }
        }

        return $result;
    }
645515
public function overwrite($filepath)
    {
        $result = $this->sendOverwrite($filepath,
            $this->handle, $this->api_key, $this->security);

        // update metadata
        $this->metadata['filename'] = $result->metadata['filename'];
        $this->metadata['mimetype'] = $result->metadata['mimetype'];
        $this->metadata['size'] = $result->metadata['size'];

        return true;
    }
375772
public function writeToFile($filePath)
    {
        $out = @fopen($filePath,"w");

        if (!$out){
            throw new AssetException($this->token,
                "The asset '".$this->token."' could not be written to path '$filePath'. Check the path is valid and the directory exists.");
        }

        $stream = $this->getStream();

        if (!$stream){
            throw new AssetException($this->token,
                "The asset '".$this->token."' could not provide a valid stream.'");
        }

        while(!feof($stream)){
            $bytes = fread($stream, 8192);
            fwrite($out, $bytes);
        }

        fclose($stream);
        fclose($out);
    }
497296
public static function save( $filePath, $value, $format = FALSE )
	{
		$writer	= new FS_File_JSON_Writer( $filePath );
		return $writer->write( $value, $format );
	}
870156
public function writeFile($filePath = null, array $options = [])
    {
        $filePath = empty($filePath)
            ? $this->filePath
            : $filePath;

        if ($this->count()) {
            $root = '<' . pathinfo($filePath, PATHINFO_FILENAME) . '/>';

            $contents = $this->getArrayCopy();
            $xml = new \SimpleXMLElement($root);
            array_walk_recursive($contents, [&$xml, 'addChild']);

            return (new File())->write($filePath, $xml->asXML());
        }
    }
775291
public function setFilePath( $filePath )
	{
		$this->filePath      = $filePath;
		$this->shortFilePath = str_replace( base_path() , '' , $filePath );

		return $this;
	}
1233712
public static function filename( $filePath, array $options = [])
    {
        extract( static::FilePathProperties($filePath) );

        $options = static::ExtendOptions($options);

        $stringOptions = static::BuildPathOptions($options);

        return sprintf( '%s/%s%s.%s', $dirname, $filename, $stringOptions, $extension );;
    }
487380
public function saveToFile($filePath,$format = 'csvforexcel')
    {
        $this->format(Format::get($format));
        $this->run();

        $this->data->saveToFile($filePath);

        return true;
    }
812919
public static boolean setInitFilePath(String filePath) {
		if (filePath!=null){
			if (init(filePath)){
				return true;
			}
			// try the file name
			String defaultPath=System.getProperty(GlobalFileProperties.class.getName()+".DefaultPath");
			String newPath=defaultPath+File.separator+filePath;
			if (init(newPath)){
				return true;
			}
		}

		String defaultPath=System.getProperty(GlobalFileProperties.class.getName()+".DefaultPath");
		if (init(defaultPath)){
			return true;
		} else {
			log.error(GlobalFileProperties.class.getName()+" No initialized width path:"+filePath+" try to set the path in System propertyes:"+GlobalFileProperties.class.getName()+".DefaultPath");
			return false;
		}
	}
865786
protected function createWritableStream ($filePath)
    {
        if (is_resource($filePath)) {
            $stream = $filePath;
        } elseif (is_string($filePath)) {
            $stream = fopen($filePath, 'wb');
            if (! $stream) {
                throw new InvalidArgumentException("Can't open file `{$filePath}` for writing.");
            }
        } else {
            $stream = tmpfile();
        }

        return $stream;
    }
17804
public function create($filePath = null, $mode = 'wb')
    {
        $filePath = isset($filePath) ? $filePath : $this->filePath;
        $dir = dirname($filePath);

        if ( ! is_writable($dir)) {
            if ( ! file_exists($dir)) {
                mkdir($dir, 0777, true);
            }
        }

        if ( ! $fp = @fopen($filePath, $mode)) {
            return false;
        }

        parent::__construct($filePath);

        return $fp;
    }