public static function writeFile(string $file, string $contents, int $permissions = 0777): string
    {
        self::createDirectory(\dirname($file));
        
        $tempFile = \tempnam(\sys_get_temp_dir(), self::TEMP_FILE_PREFIX);
        
        \file_put_contents($tempFile, $contents);
        
        if (\DIRECTORY_SEPARATOR == '\\') {
            if (\is_file($file)) {
                @\unlink($file);
            }
        }
        
        if (!@\rename($tempFile, $file)) {
            throw new \RuntimeException(\sprintf('Could not move temp file to "%s"%s', $file, self::getErrorInfo()));
        }
        
        if (\DIRECTORY_SEPARATOR != '\\') {
            self::changePermissions($file, $permissions);
        }
        
        \clearstatcache(true, $file);
        
        return $file;
    }
public static function writeFile(string $file, string $contents, int $permissions = 0777): string
    {
        self::createDirectory(\dirname($file));
        
        $tempFile = \tempnam(\sys_get_temp_dir(), self::TEMP_FILE_PREFIX);
        
        \file_put_contents($tempFile, $contents);
        
        if (\DIRECTORY_SEPARATOR == '\\') {
            if (\is_file($file)) {
                @\unlink($file);
            }
        }
        
        if (!@\rename($tempFile, $file)) {
            throw new \RuntimeException(\sprintf('Could not move temp file to "%s"%s', $file, self::getErrorInfo()));
        }
        
        if (\DIRECTORY_SEPARATOR != '\\') {
            self::changePermissions($file, $permissions);
        }
        
        \clearstatcache(true, $file);
        
        return $file;
    }
public static function writeFile ( string $ file , string $ contents , int $ permissions = 0777 ) : string { self :: createDirectory ( \ dirname ( $ file ) ) ; $ tempFile = \ tempnam ( \ sys_get_temp_dir ( ) , self :: TEMP_FILE_PREFIX ) ; \ file_put_contents ( $ tempFile , $ contents ) ; if ( \ DIRECTORY_SEPARATOR == '\\' ) { if ( \ is_file ( $ file ) ) { @ \ unlink ( $ file ) ; } } if ( ! @ \ rename ( $ tempFile , $ file ) ) { throw new \ RuntimeException ( \ sprintf ( 'Could not move temp file to "%s"%s' , $ file , self :: getErrorInfo ( ) ) ) ; } if ( \ DIRECTORY_SEPARATOR != '\\' ) { self :: changePermissions ( $ file , $ permissions ) ; } \ clearstatcache ( true , $ file ) ; return $ file ; }
Atomic file writer.

@param string $file
@param string $contents
@param int $permissions
@return string The location of the generated file.
Atomic file writer .