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);
    }