public/Set-PhpDownloadCache.ps1

Function Set-PhpDownloadCache
{
    <#
    .Synopsis
    Sets the path to a local directory where downloaded files should be cached (valid only for the current session).

    .Parameter Path
    The path to a local directory.
    If Path does not exist, it will be created.
    If Path is not specified (or if it's an empty directory), the cache will be disabled.

    .Example
    Set-PhpDownloadCache 'C:\Download\Cache'

    .Example
    Set-PhpDownloadCache
    #>

    Param (
        [Parameter(Mandatory = $False, Position = 0, HelpMessage = 'The path to a local directory; if empty, the download cache will be disabled')]
        [string]$Path
    )
    Begin {
    }
    Process {
        If ($null -eq $Path -or $Path -eq '') {
            $Path = ''
        } Else {
            $Path = [System.IO.Path]::GetFullPath($Path)
            If (Test-Path -LiteralPath $Path -PathType Leaf) {
                Throw "$Path is an existing file: the path of download cache must be a directory"
            }
            If (-Not(Test-Path -LiteralPath $Path -PathType Container)) {
                New-Item -Path $Path -ItemType Directory | Out-Null
            }
        }
        Set-Variable -Scope Script -Name 'DOWNLOADCACHE_PATH' -Value $Path -Force
    }
    End {
    }
}