Update
extends Script
in package
Uses
SortByVersionTrait, HandleExceptionTrait
Class Install
Script to update the ApiOpenStudio database.
Table of Contents
- $argMap : array<string|int, mixed>
- The command argument map array.
- $arguments : array<string|int, mixed>
- The command arguments array.
- $config : Config
- $db : ADOConnection
- $exec : string
- The current executed argument.
- $flags : array<string|int, mixed>
- The command flags array.
- $lastUpdateVersionRun : string
- $options : array<string|int, mixed>
- The command options array.
- $updateDir : string
- __construct() : mixed
- Install constructor.
- exec() : void
- Execute the function.
- load() : void
- Load arguments for the function.
- sortByVersion() : int
- Custom sort function to sort array of version string.
- findUpdates() : array<string|int, mixed>
- Find all update functions.
- getCurrentVersion() : mixed
- Get the current version from the database.
- handleException() : void
- Handle exceptions for CLI in a generic way.
- help() : void
- Abstract function help.
- readlineTerminal() : false|string
- Fetch a parameter from the command line.
- runUpdates() : mixed
- Run the update,
- timeToDie() : void
- Helper function to die.
- getArgs() : void
- Parse and store arguments.
- getValues() : void
- Either store value as single value or array of values
- validateAllowed() : void
- Validate all supplied arguments are allowed.
- validateFlags() : void
- Validate supplied flags.
- validateMultiple() : void
- Validate any supplied arguments with multiple values are allowed.
- validateOptions() : void
- Validate supplied options.
- validatePermitted() : void
- Validate against any permitted value restrictions.
- validateRequired() : void
- Validate all required options are present.
Properties
$argMap
The command argument map array.
protected
array<string|int, mixed>
$argMap
= ['options' => ['d' => ['required' => false, 'multiple' => false]], 'flags' => []]
Command argument map.
$arguments
The command arguments array.
protected
array<string|int, mixed>
$arguments
Command args.
$config
protected
Config
$config
Config class.
$db
protected
ADOConnection
$db
database connection.
$exec
The current executed argument.
protected
string
$exec
Current executed arg.
$flags
The command flags array.
protected
array<string|int, mixed>
$flags
Command flags.
$lastUpdateVersionRun
protected
string
$lastUpdateVersionRun
Last update run.
$options
The command options array.
protected
array<string|int, mixed>
$options
Command options.
$updateDir
protected
string
$updateDir
= 'includes/updates/'
Relative path to updates directory.
Methods
__construct()
Install constructor.
public
__construct() : mixed
Return values
mixed —exec()
Execute the function.
public
exec([array<string|int, mixed>|null $argv = null ]) : void
Parameters
- $argv : array<string|int, mixed>|null = null
-
CLI args.
Return values
void —load()
Load arguments for the function.
public
load(array<string|int, mixed> $argv) : void
Parameters
- $argv : array<string|int, mixed>
-
CLI args.
Return values
void —sortByVersion()
Custom sort function to sort array of version string.
public
sortByVersion(string $a, string $b) : int
This assumes example version format of: 1.2.0 1.2.1 1.2.2 1.2.3-alpha 1.2.3-alpha1 1.2.3-alpha2 1.2.3-beta 1.2.3-beta1 1.2.3-beta2 1.2.3-rc 1.2.3-rc1 1.2.3-rc2 1.2.3 1.3.0
Parameters
- $a : string
- $b : string
Return values
int —findUpdates()
Find all update functions.
protected
findUpdates(string $currentVersion) : array<string|int, mixed>
Parameters
- $currentVersion : string
-
Current version.
Return values
array<string|int, mixed> —All functions with meta.
getCurrentVersion()
Get the current version from the database.
protected
getCurrentVersion() : mixed
Tags
Return values
mixed —handleException()
Handle exceptions for CLI in a generic way.
protected
handleException(ApiException $e) : void
Parameters
- $e : ApiException
Return values
void —help()
Abstract function help.
protected
help() : void
Return values
void —readlineTerminal()
Fetch a parameter from the command line.
protected
readlineTerminal([string $prompt = '' ]) : false|string
Parameters
- $prompt : string = ''
-
Input prompt text.
Return values
false|string —Response in from the user.
runUpdates()
Run the update,
protected
runUpdates(array<string|int, mixed> $functions) : mixed
Parameters
- $functions : array<string|int, mixed>
-
Ordered array of functions name to run for the update.
Return values
mixed —timeToDie()
Helper function to die.
protected
timeToDie(string|array<string|int, mixed> $msg) : void
Parameters
- $msg : string|array<string|int, mixed>
-
Log message.
Return values
void —getArgs()
Parse and store arguments.
private
getArgs(array<string|int, mixed> $args) : void
Parameters
- $args : array<string|int, mixed>
-
Cli arguments.
Return values
void —getValues()
Either store value as single value or array of values
private
getValues(mixed $index, mixed $value) : void
Parameters
- $index : mixed
-
Option index.
- $value : mixed
-
Option value.
Return values
void —validateAllowed()
Validate all supplied arguments are allowed.
private
validateAllowed(string $name, mixed $index) : void
Parameters
- $name : string
-
Arg name.
- $index : mixed
-
Arg index.
Return values
void —validateFlags()
Validate supplied flags.
private
validateFlags() : void
Return values
void —validateMultiple()
Validate any supplied arguments with multiple values are allowed.
private
validateMultiple(string $name, mixed $value, mixed $index) : void
Parameters
- $name : string
-
Arg name.
- $value : mixed
-
Arg value.
- $index : mixed
-
Arg index.
Return values
void —validateOptions()
Validate supplied options.
private
validateOptions() : void
Return values
void —validatePermitted()
Validate against any permitted value restrictions.
private
validatePermitted(string $name, mixed $value, mixed $index) : void
Parameters
- $name : string
-
Arg name.
- $value : mixed
-
Arg value.
- $index : mixed
-
Arg index.
Return values
void —validateRequired()
Validate all required options are present.
private
validateRequired(array<string|int, mixed> $opt, mixed $index) : void
Parameters
- $opt : array<string|int, mixed>
-
Option name.
- $index : mixed
-
Option index.