public static function setContent(string $path, $data, bool $createIfDoesntExist = false)
    {
        if ($createIfDoesntExist && !is_dir(dirname($path))) {
            mkdir(dirname($path), 0777, true);
        }
        
        if (empty($data)) {
            // ignore the result because empty string returns faulty when calling file_put_contents
            file_put_contents($path, $data);
            return;
        }
        
        if (!file_put_contents($path, $data)) {
            FileException::throw($path, "Unable to write file!");
        }
    }
public static function setContent(string $path, $data, bool $createIfDoesntExist = false)
    {
        if ($createIfDoesntExist && !is_dir(dirname($path))) {
            mkdir(dirname($path), 0777, true);
        }
        
        if (empty($data)) {
            // ignore the result because empty string returns faulty when calling file_put_contents
            file_put_contents($path, $data);
            return;
        }
        
        if (!file_put_contents($path, $data)) {
            FileException::throw($path, "Unable to write file!");
        }
    }
public static function setContent ( string $ path , $ data , bool $ createIfDoesntExist = false ) { if ( $ createIfDoesntExist && ! is_dir ( dirname ( $ path ) ) ) { mkdir ( dirname ( $ path ) , 0777 , true ) ; } if ( empty ( $ data ) ) { // ignore the result because empty string returns faulty when calling file_put_contents file_put_contents ( $ path , $ data ) ; return ; } if ( ! file_put_contents ( $ path , $ data ) ) { FileException :: throw ( $ path , "Unable to write file!" ) ; } }
Set content of the file at the specified path.

@param string $path
Path of the file to set the content for.

@param mixed $data
The data to write. Can be either a string, an
array or a stream resource.

@param boolean $createIfDoesntExist
[optional]
Create the file and possibly parent directories in the path if it doesn't exist.

@throws \Exception
Set content of the file at the specified path .