src/Helpers/FileHelperAsc.php
public static function putContents($filePath, $contents, $openFlags = 'cwt', $lock = true, $createMode = null)
    {
        $lockTimeout = is_int($lock) && !empty($lock) ? $lock : null;
        $lock = !empty($lock);
        $file = static::ensureFileObject($filePath);
        $createMode = isset($createMode) ? $createMode : static::$fileCreateMode;
        $createModeStr = FileHelper::permissionsAsString($createMode);
        $unlockCallback = function ($result = null) use ($filePath, $lock) {
            if ($lock) {
                static::unlock($filePath);
            }
            if (is_object($result) && $result instanceof \Throwable) {
                throw $result;
            }
            return $result;
        };
        return static::onUnlock($filePath)
            ->then(function() use (&$file, $filePath, $lockTimeout, $openFlags, $createModeStr, $lock) {
                if ($lock) {
                    static::lock($filePath, $lockTimeout);
                }
                return $file->open($openFlags, $createModeStr);
            })->then(function(WritableStreamInterface $stream) use (&$file, $contents) {
                $stream->write($contents);
                return $file->close();
            })->then($unlockCallback, $unlockCallback);
    }
public static function putContents($filePath, $contents, $openFlags = 'cwt', $lock = true, $createMode = null)
    {
        $lockTimeout = is_int($lock) && !empty($lock) ? $lock : null;
        $lock = !empty($lock);
        $file = static::ensureFileObject($filePath);
        $createMode = isset($createMode) ? $createMode : static::$fileCreateMode;
        $createModeStr = FileHelper::permissionsAsString($createMode);
        $unlockCallback = function ($result = null) use ($filePath, $lock) {
            if ($lock) {
                static::unlock($filePath);
            }
            if (is_object($result) && $result instanceof \Throwable) {
                throw $result;
            }
            return $result;
        };
        return static::onUnlock($filePath)
            ->then(function() use (&$file, $filePath, $lockTimeout, $openFlags, $createModeStr, $lock) {
                if ($lock) {
                    static::lock($filePath, $lockTimeout);
                }
                return $file->open($openFlags, $createModeStr);
            })->then(function(WritableStreamInterface $stream) use (&$file, $contents) {
                $stream->write($contents);
                return $file->close();
            })->then($unlockCallback, $unlockCallback);
    }
Put contents into file
@param string|File $filePath
@param string      $contents
@param string      $openFlags
@param bool|int    $lock Lock file for operation and check for a lock OR lock timeout
@param int|null    $createMode
@return ExtendedPromiseInterface