VersionsHelper
extends Helper
in package
Versions Helper
Helper to read the versions of vendors/plugins for the parent app.
Uses the Composer Lock Parser to get detailed version onformation from the composer.lock file. It also uses git to try to determine the version of the application itself.
Table of Contents
Properties
- $rootDir : string
- The root directory of the application
- $_config : array<string, mixed>
- Runtime config
- $_configInitialized : bool
- Whether the config property has already been configured with defaults
- $_defaultConfig : array<string, mixed>
- Default config for this helper.
- $_helperMap : array<string, array<string|int, mixed>>
- A helper lookup table used to lazy load helper objects.
- $_View : View
- The View instance this helper is attached to
- $ComposerInfo : ComposerInfo|null
- Contains the loaded composer info.
- $composerPath : string
- The path to the composer.lock file to parse/use.
- $gitCmd : null|string
- The path to the git command.
- $helpers : array<string|int, mixed>
- List of helpers used by this helper
Methods
- __call() : mixed|void
- Provide non fatal errors on missing method calls.
- __construct() : void
- Initialize the helper
- __debugInfo() : array<string, mixed>
- Returns an array that can be used to describe the internal state of this object.
- __get() : Helper|null|void
- Lazy loads helpers.
- addClass() : array<string, mixed>
- Adds the given class to the element options
- app() : string|null
- Gets the version of this app using git
- configShallow() : $this
- Merge provided config with existing config. Unlike `config()` which does a recursive merge for nested keys, this method does a simple merge.
- getConfig() : mixed
- Returns the config.
- getConfigOrFail() : mixed
- Returns the config for this specific key.
- getPackages() : PackagesCollection<string|int, Package>
- Gets a list of all available packages
- getRootDir() : string
- Gets the root path of the application.
- getTypes() : array<int|string, mixed>
- Returns the list of available package types
- getView() : View
- Get the view instance this helper is bound to.
- implementedEvents() : array<string, mixed>
- Get the View callbacks this helper is interested in.
- initialize() : void
- Constructor hook method.
- package() : object
- Gets info on a particular package
- runGit() : array<int, string>
- Runs the git command with the args
- setConfig() : $this
- Sets the config.
- _configDelete() : void
- Deletes a single config key.
- _configRead() : mixed
- Reads a config key.
- _configWrite() : void
- Writes a config key.
- _confirm() : string
- Returns a string to be used as onclick handler for confirm dialogs.
- exec() : false|string
- Here so I can mock it mainly.
Properties
$rootDir
The root directory of the application
public
string
$rootDir
= ''
$_config
Runtime config
protected
array<string, mixed>
$_config
= []
$_configInitialized
Whether the config property has already been configured with defaults
protected
bool
$_configInitialized
= false
$_defaultConfig
Default config for this helper.
protected
array<string, mixed>
$_defaultConfig
= []
$_helperMap
A helper lookup table used to lazy load helper objects.
protected
array<string, array<string|int, mixed>>
$_helperMap
= []
$_View
The View instance this helper is attached to
protected
View
$_View
$ComposerInfo
Contains the loaded composer info.
protected
ComposerInfo|null
$ComposerInfo
= null
$composerPath
The path to the composer.lock file to parse/use.
protected
string
$composerPath
= ''
$gitCmd
The path to the git command.
protected
null|string
$gitCmd
= null
$helpers
List of helpers used by this helper
protected
array<string|int, mixed>
$helpers
= []
Methods
__call()
Provide non fatal errors on missing method calls.
public
__call(string $method, array<string|int, mixed> $params) : mixed|void
Parameters
- $method : string
-
Method to invoke
- $params : array<string|int, mixed>
-
Array of params for the method.
Return values
mixed|void__construct()
Initialize the helper
public
__construct(View $View[, array<string, mixed> $config = [] ]) : void
Parameters
- $View : View
-
The view object
- $config : array<string, mixed> = []
-
Helper config settings
Tags
__debugInfo()
Returns an array that can be used to describe the internal state of this object.
public
__debugInfo() : array<string, mixed>
Return values
array<string, mixed>__get()
Lazy loads helpers.
public
__get(string $name) : Helper|null|void
Parameters
- $name : string
-
Name of the property being accessed.
Return values
Helper|null|void —Helper instance if helper with provided name exists
addClass()
Adds the given class to the element options
public
addClass(array<string, mixed> $options, string $class[, string $key = 'class' ]) : array<string, mixed>
Parameters
- $options : array<string, mixed>
-
Array options/attributes to add a class to
- $class : string
-
The class name being added.
- $key : string = 'class'
-
the key to use for class. Defaults to
'class'
.
Return values
array<string, mixed> —Array of options with $key set.
app()
Gets the version of this app using git
public
app() : string|null
Return values
string|null —The version according to git
configShallow()
Merge provided config with existing config. Unlike `config()` which does a recursive merge for nested keys, this method does a simple merge.
public
configShallow(array<string, mixed>|string $key[, mixed|null $value = null ]) : $this
Setting a specific value:
$this->configShallow('key', $value);
Setting a nested value:
$this->configShallow('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->configShallow(['one' => 'value', 'another' => 'value']);
Parameters
- $key : array<string, mixed>|string
-
The key to set, or a complete array of configs.
- $value : mixed|null = null
-
The value to set.
Return values
$thisgetConfig()
Returns the config.
public
getConfig([string|null $key = null ][, mixed $default = null ]) : mixed
Usage
Reading the whole config:
$this->getConfig();
Reading a specific value:
$this->getConfig('key');
Reading a nested value:
$this->getConfig('some.nested.key');
Reading with default value:
$this->getConfig('some-key', 'default-value');
Parameters
- $key : string|null = null
-
The key to get or null for the whole config.
- $default : mixed = null
-
The return value when the key does not exist.
Return values
mixed —Configuration data at the named key or null if the key does not exist.
getConfigOrFail()
Returns the config for this specific key.
public
getConfigOrFail(string $key) : mixed
The config value for this key must exist, it can never be null.
Parameters
- $key : string
-
The key to get.
Tags
Return values
mixed —Configuration data at the named key
getPackages()
Gets a list of all available packages
public
getPackages([int $list = 0 ][, null|string $type = null ]) : PackagesCollection<string|int, Package>
Parameters
- $list : int = 0
-
What list of packages should we return. 0 - Both dev and production. 1 - Just production. 2 - Just dev.
- $type : null|string = null
-
If given, only packages of this type are returned
Return values
PackagesCollection<string|int, Package> —a list of package objects
getRootDir()
Gets the root path of the application.
public
getRootDir() : string
Also verifies that it's correct each time this function is ran.
Tags
Return values
string —The path to the root folder
getTypes()
Returns the list of available package types
public
getTypes() : array<int|string, mixed>
Return values
array<int|string, mixed> —the list of found/available packages
getView()
Get the view instance this helper is bound to.
public
getView() : View
Return values
View —The bound view instance.
implementedEvents()
Get the View callbacks this helper is interested in.
public
implementedEvents() : array<string, mixed>
By defining one of the callback methods a helper is assumed to be interested in the related event.
Override this method if you need to add non-conventional event listeners. Or if you want helpers to listen to non-standard events.
Return values
array<string, mixed>initialize()
Constructor hook method.
public
initialize(array<string, mixed> $config) : void
Implement this method to avoid having to overwrite the constructor and call parent.
Parameters
- $config : array<string, mixed>
-
The configuration settings provided to this helper.
package()
Gets info on a particular package
public
package(string $name) : object
Parameters
- $name : string
-
The full name of the composer package ex: fr3nch13/utilities
Tags
Return values
object —the object that has the info of that package
runGit()
Runs the git command with the args
public
runGit([array<string|int, string> $args = [] ][, bool $addSafe = false ]) : array<int, string>
Parameters
- $args : array<string|int, string> = []
-
List of arguments to pass to the git command
- $addSafe : bool = false
-
If git complains about a "fatal: detected dubious ownership in repository at" error, add it.
Tags
Return values
array<int, string> —The result of the git command
setConfig()
Sets the config.
public
setConfig(array<string, mixed>|string $key[, mixed|null $value = null ][, bool $merge = true ]) : $this
Usage
Setting a specific value:
$this->setConfig('key', $value);
Setting a nested value:
$this->setConfig('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->setConfig(['one' => 'value', 'another' => 'value']);
Parameters
- $key : array<string, mixed>|string
-
The key to set, or a complete array of configs.
- $value : mixed|null = null
-
The value to set.
- $merge : bool = true
-
Whether to recursively merge or overwrite existing config, defaults to true.
Tags
Return values
$this_configDelete()
Deletes a single config key.
protected
_configDelete(string $key) : void
Parameters
- $key : string
-
Key to delete.
Tags
_configRead()
Reads a config key.
protected
_configRead(string|null $key) : mixed
Parameters
- $key : string|null
-
Key to read.
_configWrite()
Writes a config key.
protected
_configWrite(array<string, mixed>|string $key, mixed $value[, string|bool $merge = false ]) : void
Parameters
- $key : array<string, mixed>|string
-
Key to write to.
- $value : mixed
-
Value to write.
- $merge : string|bool = false
-
True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.
Tags
_confirm()
Returns a string to be used as onclick handler for confirm dialogs.
protected
_confirm(string $okCode, string $cancelCode) : string
Parameters
- $okCode : string
-
Code to be executed after user chose 'OK'
- $cancelCode : string
-
Code to be executed after user chose 'Cancel'
Return values
string —"onclick" JS code
exec()
Here so I can mock it mainly.
protected
exec(string $command[, array<int, string> &$output = [] ][, int &$result_code = 0 ]) : false|string
Parameters
- $command : string
-
The external command to run.
- $output : array<int, string> = []
-
The full output of the command, each line an entry in an array
- $result_code : int = 0
-
The exit code of the command
Return values
false|string —The last line of the output, or false if the command failed.