Documentation, format class, no modification. (#7629)

This commit is contained in:
frytimo
2025-11-19 12:48:36 -04:00
committed by GitHub
parent 0ea256fce8
commit 34821bed7e
36 changed files with 12982 additions and 11551 deletions

View File

@@ -28,6 +28,7 @@
/**
* Container object for creating command line options when creating a service
*
* @author Tim Fry <tim@fusionpbx.com>
*/
class command_option {
@@ -52,9 +53,11 @@ class command_option {
}
/**
* A factory method to create a new command_option
* @param type $options
* @return command_option
* Creates a new instance of CommandOption with automatically assigned properties.
*
* @param array $options Key/Value pairs to assign as properties on the new instance.
*
* @return command_option Returns a populated instance of command_option.
*/
public static function new(...$options): command_option {
$obj = new command_option();
@@ -67,6 +70,15 @@ class command_option {
}
// used to parse object values when created
/**
* Recursively parses the provided options array and applies its values to the given object.
*
* @param mixed $obj The object whose properties will be updated with the parsed options
* @param array $options The associative array containing the options to parse and apply
*
* @return void This method does not return a value, it updates the provided object instead.
*/
private static function parse_options($obj, $options) {
foreach ($options as $key => $value) {
if (is_array($value)) {
@@ -81,9 +93,63 @@ class command_option {
}
}
/**
* Appends the callback function to the array of existing callback functions
*
* @param string|null $function When function param is set, the callback function will be appended to the list of
* functions. When called without a param, the array will be returned of current
* callbacks.
*
* @return $this|array Returns the array of callbacks if no parameters passed or this object when appending a
* callback
*/
public function callback(?string $function = null) {
if ($function !== null) {
$this->functions += [$function];
return $this;
}
return $this->functions;
}
/**
* Appends the callback function to the array of existing callback functions
*
* @param string|null $function When function param is set, the callback function will be appended to the list of
* functions. When called without a param, the array will be returned of current
* callbacks.
*
* @return $this|array Returns the array of callbacks if no parameters passed or this object when appending a
* callback
*/
public function function_append(?string $function = null) {
if ($function !== null) {
$this->functions += [$function];
return $this;
}
return $this->functions;
}
/**
* Converts the current object to an array.
*
* @return array The array representation of the current object, containing
* information about options and functions.
*/
public function to_array(): array {
$array['short_option'] = $this->short_option();
$array['long_option'] = $this->long_option();
$array['description'] = $this->description();
$array['short_description'] = $this->short_description();
$array['long_description'] = $this->long_description();
$array['functions'] = $this->functions();
return $array;
}
/**
* Sets or returns the short option value
*
* @param string|null $short_option
*
* @return $this
*/
public function short_option(?string $short_option = null) {
@@ -96,7 +162,9 @@ class command_option {
/**
* Sets or returns the long option value
*
* @param string|null $long_option
*
* @return $this
*/
public function long_option(?string $long_option = null) {
@@ -109,7 +177,9 @@ class command_option {
/**
* Set the general description
*
* @param string|null $description
*
* @return $this
*/
public function description(?string $description = null) {
@@ -122,7 +192,10 @@ class command_option {
/**
* Sets or returns the short_description. If short_description is empty then the short_option is used as a default.
* @param string|null $short_description When parameter is null, it returns the currently set value. When not null the short description is set to the passed value.
*
* @param string|null $short_description When parameter is null, it returns the currently set value. When not null
* the short description is set to the passed value.
*
* @return $this
*/
public function short_description(?string $short_description = null) {
@@ -145,8 +218,11 @@ class command_option {
/**
* Sets or returns the long_description. If long_description is empty then the long_option is used as a default.
* @param string|null $long_description When parameter is null, it returns the currently set value. When not null the long description is set to the passed value.
* @return $this
*
* @param string|null $long_description When parameter is null, it returns the currently set value. When not null
* the long description is set to the passed value.
*
* @return self|string
*/
public function long_description(?string $long_description = null) {
if ($long_description !== null) {
@@ -167,9 +243,13 @@ class command_option {
}
/**
* Adds an array of callback functions replacing the existing callback functions
* @param array|null $functions
* @return $this
* Sets or retrieves the array of callback functions
*
* @param array|null $functions When functions param is set, the array will be assigned to the list of callbacks.
* When called without a parameter, the current array of callbacks will be returned.
*
* @return $this|array Returns the array of callbacks if no parameters passed or this object when setting a new
* array
*/
public function functions(?array $functions = null) {
if ($functions !== null) {
@@ -178,46 +258,6 @@ class command_option {
}
return $this->functions;
}
/**
* Appends the callback function to the array of existing callback functions
* @param string|null $function When function param is set, the callback function will be appended to the list of functions. When called without a param, the array will be returned of current callbacks.
* @return $this|array Returns the array of callbacks if no parameters passed or this object when appending a callback
*/
public function callback(?string $function = null) {
if ($function !== null) {
$this->functions += [$function];
return $this;
}
return $this->functions;
}
/**
* Appends the callback function to the array of existing callback functions
* @param string|null $function
* @return $this
*/
public function function_append(?string $function = null) {
if ($function !== null) {
$this->functions += [$function];
return $this;
}
return $this->functions;
}
/**
* Returns the array structure required for service
* @return array
*/
public function to_array(): array {
$array['short_option'] = $this->short_option();
$array['long_option'] = $this->long_option();
$array['description'] = $this->description();
$array['short_description'] = $this->short_description();
$array['long_description'] = $this->long_description();
$array['functions'] = $this->functions();
return $array;
}
}
/* Examples