• Full name: \App\Infrastructure\Services\Updater
  • This class is marked as final and can't be subclassed
  • This class is a Final class

Constants

Constant Visibility Type Value
NO_UPDATE_AVAILABLE public 0
ERROR_VERSION_CHECK public 20
ERROR_TEMP_DIR public 30
ERROR_INSTALL_DIR public 35
ERROR_DOWNLOAD_UPDATE public 40
ERROR_DELETE_TEMP_UPDATE public 50
ERROR_SIMULATE public 70

Properties

latestVersion

public ?string $latestVersion

updates

private array $updates

cache

private ?\Psr\SimpleCache\CacheInterface $cache

log

private ?\Psr\Log\LoggerInterface $log

simulationResults

private array $simulationResults

tempDir

private string $tempDir

installDir

private string $installDir

branch

private string $branch

username

private string $username

password

private string $password

onEachUpdateFinishCallbacks

private array $onEachUpdateFinishCallbacks

onAllUpdateFinishCallbacks

private array $onAllUpdateFinishCallbacks

sslVerifyHost

private bool $sslVerifyHost

updateUrl

protected string $updateUrl

updateFile

protected string $updateFile

currentVersion

protected ?string $currentVersion

dirPermissions

public int $dirPermissions

updateScriptName

public string $updateScriptName

cacheTtl

public int $cacheTtl

Methods

__construct

Create new instance

public __construct(string|null $tempDir = null, string|null $installDir = null, int $maxExecutionTime = 60): mixed

Parameters:

Parameter Type Description
$tempDir string|null
$installDir string|null
$maxExecutionTime int

Throws:


setTempDir

Set the temporary download directory.

public setTempDir(string $dir): bool

Parameters:

Parameter Type Description
$dir string

setInstallDir

Set the installation directory.

public setInstallDir(string $dir): bool

Parameters:

Parameter Type Description
$dir string

setUpdateFile

Set the update filename.

public setUpdateFile(string $updateFile): \App\Infrastructure\Services\Updater

Parameters:

Parameter Type Description
$updateFile string

setUpdateUrl

Set the update filename.

public setUpdateUrl(string $updateUrl): \App\Infrastructure\Services\Updater

Parameters:

Parameter Type Description
$updateUrl string

setBranch

Set the update branch.

public setBranch(string $branch): \App\Infrastructure\Services\Updater

Parameters:

Parameter Type Description
$branch string branch

setCache

Set the cache component.

public setCache(\Psr\SimpleCache\CacheInterface $adapter, int $ttl): \App\Infrastructure\Services\Updater

Parameters:

Parameter Type Description
$adapter \Psr\SimpleCache\CacheInterface
$ttl int

setCurrentVersion

Set the version of the current installed software.

public setCurrentVersion(string $currentVersion): \App\Infrastructure\Services\Updater

Parameters:

Parameter Type Description
$currentVersion string

setBasicAuth

Set username and password for basic authentication.

public setBasicAuth(string $username, string $password): \App\Infrastructure\Services\Updater

Parameters:

Parameter Type Description
$username string
$password string

useBasicAuth

Set authentication header if username and password exist.

private useBasicAuth(): null|resource

setLogger

Replace the logger internally used by the given logger instance.

public setLogger(\Psr\Log\LoggerInterface $logger): \App\Infrastructure\Services\Updater

Parameters:

Parameter Type Description
$logger \Psr\Log\LoggerInterface

getVersionsToUpdate

Get an array of versions which will be installed.

public getVersionsToUpdate(): array

getSslVerifyHost

public getSslVerifyHost(): bool

setSslVerifyHost

public setSslVerifyHost(bool $sslVerifyHost): \App\Infrastructure\Services\Updater

Parameters:

Parameter Type Description
$sslVerifyHost bool

checkUpdate

Check for a new version

public checkUpdate(int $timeout = 10): int|bool

Parameters:

Parameter Type Description
$timeout int Download timeout in seconds (Only applied for downloads via curl)

Return Value:

true: New version is available false: Error while checking for update int: Status code (i.e. Updater::NO_UPDATE_AVAILABLE)

Throws:


newVersionAvailable

Check if a new version is available.

public newVersionAvailable(): bool

isValidUrl

Check if url is valid.

protected isValidUrl(string $url): bool

Parameters:

Parameter Type Description
$url string

downloadCurl

Download file via curl.

protected downloadCurl(string $url, int $timeout = 10): string|false

Parameters:

Parameter Type Description
$url string URL to file
$timeout int

downloadUpdate

Download the update

protected downloadUpdate(string $updateUrl, string $updateFile): bool

Parameters:

Parameter Type Description
$updateUrl string Url where to download from
$updateFile string Path where to save the download

Throws:


simulateInstall

Simulate update process.

protected simulateInstall(string $updateFile): bool

Parameters:

Parameter Type Description
$updateFile string

install

Install update.

protected install(string $updateFile, int|bool $simulateInstall, string $version): int|bool

Parameters:

Parameter Type Description
$updateFile string Path to the update file
$simulateInstall int|bool Check for directory and file permissions instead of installing the update
$version string

update

Update to the latest version

public update(bool $simulateInstall = true, bool $deleteDownload = true): int|bool

Parameters:

Parameter Type Description
$simulateInstall bool Check for directory and file permissions before copying files (Default: true)
$deleteDownload bool Delete download after update (Default: true)

Throws:


onEachUpdateFinish

Add callback which is executed after each update finished.

public onEachUpdateFinish(callable $callback): $this

Parameters:

Parameter Type Description
$callback callable

setOnAllUpdateFinishCallbacks

Add callback which is executed after all updates finished.

public setOnAllUpdateFinishCallbacks(callable $callback): $this

Parameters:

Parameter Type Description
$callback callable

runOnEachUpdateFinishCallbacks

Run callbacks after each update finished.

private runOnEachUpdateFinishCallbacks(string $updateVersion, bool $simulate): void

Parameters:

Parameter Type Description
$updateVersion string
$simulate bool

runOnAllUpdateFinishCallbacks

Run callbacks after all updates finished.

private runOnAllUpdateFinishCallbacks(array $updatedVersions): void

Parameters:

Parameter Type Description
$updatedVersions array