The library for installing and updating snippets, plugins, and libraries from GitHub and GitLab repositories.
- “Site” — your site.
- “Resource” — snippet, plugin or library that you want to install or update.
- First, the library downloads the repository archive of Resource from GitHub or GitLab using API and temporary saves it in
assets/cache/ddInstaller/. - Then it decides whether to install / update Resource or not.
To do this it looks at thecomposer.jsonfile from the archive and compares withcomposer.jsonof Resource on your Site:- Resource will be installed or updated if:
composer.jsonin the archive:- Is exist.
- And not empty.
- And contains the valid
versionfield.
composer.jsonon Site:- Is not exist.
- Or empty.
- Or doesn't contain the
versionfield. - Or the
versionfield is invalid.
versionin the archive >versionon Site.
- Otherwise, Resource will not be installed.
- Resource will be installed or updated if:
- To avoid accumulation of trash files, the library removes the existing Resource folder before installation and creates it again (e. g.
assets/snippets/ddGetDate/). - If Resource is a snippet or plugin, the library tries to find its DB file (e. g.
ddGetDate_snippet.php) and installs / upates it to DB. - Finally, the library copies remaining files and subfolders to the Resource folder.
- PHP >= 7.4
- (MODX)EvolutionCMS >= 1.1
- (MODX)EvolutionCMS.libraries.ddTools >= 0.63
- (MODX)EvolutionCMS.snippets.ddMakeHttpRequest >= 2.4
Elements → Manage Files:
- Create a new folder
assets/libs/ddInstaller/. - Extract the archive to the folder.
Installs or updates needed snippet, plugin, or library.
-
$params- Description: Parameters, the pass-by-name style is used.
- Valid values:
arrayAssociativeobjectstringJsonObject— as JSONstringHjsonObject— as HJSONstringQueryFormatted— as Query string
- Required
-
$params->url- Description: Resource GitHub or GitLab URL.
- Repository root URL only — without
/-/tree/...,/-/blob/...and other path suffixes. - E. g.
'https://github.com/DivanDesign/EvolutionCMS.snippets.ddGetDate' - E. g.
'https://gitlab.com/DivanDesign/SomeGroup/EvolutionCMS.snippets.ddGetDate'
- Repository root URL only — without
- Valid values:
stringUrl - Required
- Description: Resource GitHub or GitLab URL.
-
$params->revision- Description: The branch name, tag name, or commit hash to retrieve.
- If you specify anything other than
'master'/'main'or any version tag, the distributive will be installed regardless of thecomposer.jsonversion. This is useful for installing developer versions.
- If you specify anything other than
- Valid values:
string - Default value:
'master'
- Description: The branch name, tag name, or commit hash to retrieve.
-
$params->type- Description: Resource type.
- The parameter is case insensitive.
- If
$params->urlcontain the following words, you can avoid this parameter and the method will detect type automatically:'snippet','snippets'—'snippet''plugin','plugins'—'plugin''library','libraries'—'library'
- Valid values:
'snippet''plugin''library'- any empty value — will be auto detected from
$params->url
- Default value: —
- Description: Resource type.
-
$params->token- Description: Access token for private repositories.
- GitHub: Personal Access Token (classic:
reposcope, fine-grained:Contents: Read-only). - GitLab: Personal Access Token with
read_apiscope (archive API does not acceptread_repository, see gitlab#28324).
- GitHub: Personal Access Token (classic:
- Valid values:
string - Default value: —
- Description: Access token for private repositories.
$result- Description: Installation status.
- Valid values:
true— if the resource is installed or updated successfullyfalse— if something went wrong or the resource on Site is already up to date
Just run the following PHP code in your sources or Console:
// Include (MODX)EvolutionCMS.libraries.ddInstaller
require_once(
$modx->getConfig('base_path')
. 'assets/libs/ddInstaller/require.php'
);
// Install (MODX)EvolutionCMS.snippets.ddGetDate
\DDInstaller::install([
'url' => 'https://github.com/DivanDesign/EvolutionCMS.snippets.ddGetDate',
]);- If
ddGetDateis not exist on your Site, the library will just install it. - If
ddGetDateis already exist on your Site, the library will check it version and update it if needed.
// Include (MODX)EvolutionCMS.libraries.ddInstaller
require_once(
$modx->getConfig('base_path')
. 'assets/libs/ddInstaller/require.php'
);
// Install from gitlab.com
\DDInstaller::install([
// This is not a valid URL, just an example
'url' => 'https://gitlab.com/DivanDesign/SomeGroup/EvolutionCMS.snippets.ddGetDate',
]);// Include (MODX)EvolutionCMS.libraries.ddInstaller
require_once(
$modx->getConfig('base_path')
. 'assets/libs/ddInstaller/require.php'
);
// GitHub
\DDInstaller::install([
'url' => 'https://github.com/org/EvolutionCMS.snippets.ddGetDate',
// Your GitHub Personal Access Token
'token' => 'ghp_xxxxxxxx',
]);
// GitLab
\DDInstaller::install([
'url' => 'https://gitlab.com/group/EvolutionCMS.snippets.ddGetDate',
// Your GitLab Personal Access Token
'token' => 'glpat-xxxxxxxx',
]);