From 97873674df1751d8a7245458c3e04cf497239022 Mon Sep 17 00:00:00 2001 From: Yuri Salimovskiy Date: Wed, 17 May 2023 09:53:21 +0300 Subject: [PATCH 1/3] Added `cli_boot` extension hook to run on each CLI request --- .../extension-hooks-overview.md | 1 + .../development/extension-hooks/global/cli.md | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 docs/development/extension-hooks/global/cli.md diff --git a/docs/development/extension-hooks/extension-hooks-overview.md b/docs/development/extension-hooks/extension-hooks-overview.md index 7bac8c885..1218c498b 100644 --- a/docs/development/extension-hooks/extension-hooks-overview.md +++ b/docs/development/extension-hooks/extension-hooks-overview.md @@ -20,6 +20,7 @@ TIP: Reference [Extending The Core](development/extensions.md) for more informat Core hooks are categorized into 5 categories: - Global - [Core Library](development/extension-hooks/global/core.md) + - [CLI](development/extension-hooks/global/cli.md) - [Email Library](development/extension-hooks/global/email.md) - [Filemanager Library](development/extension-hooks/global/filemanager.md) - [Functions Library](development/extension-hooks/global/functions.md) diff --git a/docs/development/extension-hooks/global/cli.md b/docs/development/extension-hooks/global/cli.md new file mode 100644 index 000000000..9ff7ee93c --- /dev/null +++ b/docs/development/extension-hooks/global/cli.md @@ -0,0 +1,56 @@ +--- +lang: php +--- + + + +# CLI Extension Hooks + +### `cli_boot($cli, $commandClassName, $commandObject)` + +| Parameter | Type | Description | +| ------------------ | -------- | ------------------------------------------------------------------------ | +| \$cli | `Object` | Instance of CLI currently running | +| \$commandClassName | `String` | Class name of command to be executed | +| \$commandObject | `Object` | Instance of command class to be executed | +| Returns | `Object` | Modified instance of `$commandObject` | + +Run tasks on every CLI request. Allows running the code before certain CLI command is run as well as modification of command class instance. + +How it's called: + + $command = ee()->extensions->call('cli_boot', $this, $commandClass, $command); + if (ee()->extensions->end_script === true) { + $this->complete(''); + } + +### `core_template_route($uri_string)` + +| Parameter | Type | Description | +| ------------ | -------- | ------------------------------------------------------------------------ | +| \$uri_string | `String` | Current URI string | +| Returns | `Array` | Array containing the name of the template group and template (see below) | + +Reassign the template group and template loaded for parsing. + +How it's called: + + $edata = ee()->extensions->call('core_template_route', ee()->uri->uri_string); + if (is_array($edata) && count($edata) == 2) + { + list($template_group, $template) = $edata; + } + +Example of array to return: + + array( + 'template_group', // Template group name + 'template' // Template name + ); From 7f52544c0d7220026111b2de039b381a1407254e Mon Sep 17 00:00:00 2001 From: Yuri Salimovskiy Date: Tue, 14 Nov 2023 10:46:49 +0200 Subject: [PATCH 2/3] Update cli.md --- .../development/extension-hooks/global/cli.md | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/docs/development/extension-hooks/global/cli.md b/docs/development/extension-hooks/global/cli.md index 9ff7ee93c..1c0e01c1f 100644 --- a/docs/development/extension-hooks/global/cli.md +++ b/docs/development/extension-hooks/global/cli.md @@ -18,39 +18,31 @@ lang: php | Parameter | Type | Description | | ------------------ | -------- | ------------------------------------------------------------------------ | | \$cli | `Object` | Instance of CLI currently running | -| \$commandClassName | `String` | Class name of command to be executed | -| \$commandObject | `Object` | Instance of command class to be executed | -| Returns | `Object` | Modified instance of `$commandObject` | +| Returns | `Void` | | -Run tasks on every CLI request. Allows running the code before certain CLI command is run as well as modification of command class instance. +Run tasks on every CLI request. Allows running the code before certain CLI command. How it's called: - $command = ee()->extensions->call('cli_boot', $this, $commandClass, $command); + $command = ee()->extensions->call('cli_boot', $this); if (ee()->extensions->end_script === true) { $this->complete(''); } -### `core_template_route($uri_string)` +### `cli_before_handle($cli, $command, $commandClass)` -| Parameter | Type | Description | -| ------------ | -------- | ------------------------------------------------------------------------ | -| \$uri_string | `String` | Current URI string | -| Returns | `Array` | Array containing the name of the template group and template (see below) | +| Parameter | Type | Description | +| -------------- | -------- | ------------------------------------------------------------------------ | +| \$cli | `Object` | Instance of CLI currently running | +| \$commandClass | `String` | Class name of command to be executed | +| \$command | `Object` | Instance of command class to be executed | +| Returns | `Object` | Modified instance of `$command` | -Reassign the template group and template loaded for parsing. +Run tasks right before CLI command is excuted. Allows modification of command class instance. How it's called: - $edata = ee()->extensions->call('core_template_route', ee()->uri->uri_string); - if (is_array($edata) && count($edata) == 2) - { - list($template_group, $template) = $edata; + $command = ee()->extensions->call('cli_before_handle', $this, $command, $commandClass); + if (ee()->extensions->end_script === true) { + $this->complete(''); } - -Example of array to return: - - array( - 'template_group', // Template group name - 'template' // Template name - ); From 9e84e5f057e6e0de1ce2aabc802ade34b913e11d Mon Sep 17 00:00:00 2001 From: Yuri Salimovskiy Date: Tue, 14 Nov 2023 11:28:21 +0200 Subject: [PATCH 3/3] Update cli.md --- docs/development/extension-hooks/global/cli.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/development/extension-hooks/global/cli.md b/docs/development/extension-hooks/global/cli.md index 1c0e01c1f..f29d3ed25 100644 --- a/docs/development/extension-hooks/global/cli.md +++ b/docs/development/extension-hooks/global/cli.md @@ -13,14 +13,14 @@ lang: php # CLI Extension Hooks -### `cli_boot($cli, $commandClassName, $commandObject)` +### `cli_boot($cli)` | Parameter | Type | Description | | ------------------ | -------- | ------------------------------------------------------------------------ | | \$cli | `Object` | Instance of CLI currently running | | Returns | `Void` | | -Run tasks on every CLI request. Allows running the code before certain CLI command. +Run tasks before every CLI request. How it's called: @@ -29,7 +29,7 @@ How it's called: $this->complete(''); } -### `cli_before_handle($cli, $command, $commandClass)` +### `cli_before_handle($cli, $commandClass, $command)` | Parameter | Type | Description | | -------------- | -------- | ------------------------------------------------------------------------ | @@ -42,7 +42,7 @@ Run tasks right before CLI command is excuted. Allows modification of command cl How it's called: - $command = ee()->extensions->call('cli_before_handle', $this, $command, $commandClass); + $command = ee()->extensions->call('cli_before_handle', $this, $commandClass, $command); if (ee()->extensions->end_script === true) { $this->complete(''); }