HelPHP

API Documentation

Table of Contents

Namespaces

helPHP

Constants

ALLOWED_VARS  : mixed = ['$_SESSION', '$_POST', '$_GET', '$_SERVER', '$...
Naming convention checker for helPHP converted modules.

Functions

backup_instance()  : string
The backup instance utils create a backup of your HelPHP instance including the main db indicated in the db config (not the central one if it exist)
beautify_module_list()  : array<string|int, mixed>
beautify_module_list is used during install or uninstall module to insert suppress module configuration into module list config in main.php file... it just do the job to keep is readable .
check_replication()  : string
The check replica utils is checking is the master slave replication is still operationnal.
make_constants_js()  : string|files
The constants utils is used to make/update a js file with all needed constants like some translations, basic context infos etc, anything that is necessary to make run js parts of modules and helPHP js libs
convert_module()  : mixed
upgrade()  : mixed
get_string_between()  : mixed
create_module()  : string
create a basic module for helPHP
make_install()  : string
create everything needed for installing a module
recurse_ls()  : mixed
to get the list of file and folder
generate_index()  : mixed
index_association_columns()  : mixed
Give every association column (id_x) an index in the tables copied from generated/sql_objects.
beautify_db_writing()  : mixed
create_object_sql_from_table()  : string
Create the json file describing a table in generated/sql_objects
missing_association_indexes()  : array<string|int, mixed>
Association columns that are not the leading column of any index, in the current database.
block_definition_is_valid()  : bool
Checks that the field definitions of a block declaration are themselves valid JSON.
install_blocks()  : mixed
install_instance()  : mixed
install_module()  : string
Install a module in the instance and add a menu in admin hierarchy
super_copy()  : mixed
super_mkdir()  : mixed
job_manager()  : mixed
here is our buddy the job manager, made to be run as a command an working with "jobs" database as a job pile.
new_job()  : void
to add a new job in "jobs" database pile
cancel_job()  : void
Cancel a job and move if from db to history
set_status_job()  : void
Change the status of a job in the pile.
get_job_progress()  : string
Get the progression of a job
job_loop()  : void
The job loop will run until there is no more job to do, so it must be started at start of the server and it will go on infine loop waiting for job to execute.
mcp_server()  : mixed
minify()  : string|files
Minify an instance : Take all js files to create only one js.gz file the same for the CSS theme.
writeUTF8File()  : mixed
process_launcher()  : mixed
launch process in background and store their progress in redis, it's a subprocess script for helPHP\libs\utils\system_process_with_tracking
rules_signature()  : array<string|int, mixed>
Signature of the rules of one source, to tell whether two sources carry the same CSS.
count_rows()  : mixed
duplicate_groups()  : array<string|int, mixed>
Duplicated sources, grouped by their identity.
restore_symlink()  : string
Restore all the symlinks for an instance, start with the external JS one and then process every module installed
is_camel_case()  : bool
to_snake_case()  : string
bare_name()  : string
check_file()  : array<string|int, mixed>
apply_renames()  : string
interactive_rename()  : void
uninstall_module()  : string
Uninstall a module in the instance and
helphp_ws_say()  : mixed
helphp_ws_fail()  : mixed
helphp_ws_config_value()  : array<string|int, mixed>
Reads a constant value out of a config file, without including it (the class may already be loaded with older values).
helphp_ws_config_ensure()  : int
Adds the constants a previous installer did not know, before the closing brace.
helphp_ws_send()  : void
Sends one masked text frame, as a browser does.
helphp_ws_read()  : array<string|int, mixed>|null
Reads one frame, answering pings on the way. Returns [opcode, payload].
helphp_ws_probe()  : int
End-to-end check: a real socket subscribes, a real publish is delivered.

Constants

ALLOWED_VARS

Naming convention checker for helPHP converted modules.

public mixed ALLOWED_VARS = ['$_SESSION', '$_POST', '$_GET', '$_SERVER', '$_COOKIE', '$_FILES', '$_ENV', '$_REQUEST', '$CONFIG', '$DB']

Detects camelCase identifiers that should be snake_case. When run from a terminal, proposes and applies renames interactively.

Checks:

  • variable names ($myVar → $my_var)
  • function definitions (function getData → function get_data)
  • instance method/property calls ($obj->getData → $obj->get_data)
  • static method calls (Class::getData → Class::get_data)

Usage: php test_naming_convention.php path/to/Module.php [more.php|dir/]

Functions

backup_instance()

The backup instance utils create a backup of your HelPHP instance including the main db indicated in the db config (not the central one if it exist)

backup_instance(mixed $target) : string

can be called from cli with instance path as argument: php helphp/utils/backup.php instance_home_path

Parameters
$target : mixed

the home path

Return values
string —

echoing results

beautify_module_list()

beautify_module_list is used during install or uninstall module to insert suppress module configuration into module list config in main.php file... it just do the job to keep is readable .

beautify_module_list(mixed|array<string|int, mixed> $module_list, mixed|array<string|int, mixed> $temporary_module) : array<string|int, mixed>

And if you're asking what is $temporary_module ? It's a surprise ;) job in progress..

Parameters
$module_list : mixed|array<string|int, mixed>
$temporary_module : mixed|array<string|int, mixed>
Return values
array<string|int, mixed> —

the module list beautified

check_replication()

The check replica utils is checking is the master slave replication is still operationnal.

check_replication(mixed $target) : string

the user used for connection must have "SUPER" or "SLAVE MONITOR" privilege can be called from cli with instance path as argument: php helphp/utils/check_replica.php instance_home_path

Parameters
$target : mixed

the home path of the instance to get db config

Return values
string —

echoing results

make_constants_js()

The constants utils is used to make/update a js file with all needed constants like some translations, basic context infos etc, anything that is necessary to make run js parts of modules and helPHP js libs

make_constants_js(mixed $target) : string|files

can be called from cli with instance path as argument: php helphp/utils/constants.php instance_home_path

Parameters
$target : mixed

the home path of the instance to get config

Return values
string|files —

echoing results and js/constants*.js files in the instance.

convert_module()

convert_module(mixed $module_path, mixed $module_name) : mixed
Parameters
$module_path : mixed
$module_name : mixed

upgrade()

upgrade(mixed $public_admin, mixed $old_module_name, mixed $module_name, mixed $old_file, mixed $new_file) : mixed
Parameters
$public_admin : mixed
$old_module_name : mixed
$module_name : mixed
$old_file : mixed
$new_file : mixed

get_string_between()

get_string_between(mixed $string, mixed $start, mixed $end) : mixed
Parameters
$string : mixed
$start : mixed
$end : mixed

create_module()

create a basic module for helPHP

create_module(string $module_name) : string

To call from CLI php create_module.php module_name

Parameters
$module_name : string

name of the module

Return values
string —

error or success message

make_install()

create everything needed for installing a module

make_install(string $module_name, string $object_list[, bool $sql_only = false ][, mixed $public = true ]) : string

Will create the file install.php with sql query and list of file needed inside. Will also create both index.php for admin and public

To call from CLI php create_module_installer.php module_name sql_object1,sql_object2,... true|false if the module has no db php create_module_installer.php module_name no_db

Parameters
$module_name : string

name of the module

$object_list : string

sql object of the module name separated by a ','

$sql_only : bool = false

Optional. True, only create the sql part, ignore file

$public : mixed = true
Return values
string —

error or success message

recurse_ls()

to get the list of file and folder

recurse_ls(mixed $path[, mixed $base_path = '' ]) : mixed

modified version of filesystem.php to also be used by CLI call

Parameters
$path : mixed
$base_path : mixed = ''

generate_index()

generate_index(mixed $module_name, mixed $path, mixed $public) : mixed
Parameters
$module_name : mixed
$path : mixed
$public : mixed

index_association_columns()

Give every association column (id_x) an index in the tables copied from generated/sql_objects.

index_association_columns(mixed $tables) : mixed

The schema layer indexes those columns by itself (DB::sql_from_json()), but the generated installer is also the document a module ships: it has to declare the key its joins rely on, and an older toolkit reading it then still creates the index.

Parameters
$tables : mixed

create_object_sql_from_table()

Create the json file describing a table in generated/sql_objects

create_object_sql_from_table(string $instance_path, string $table_name[, mixed $CLI = false ]) : string

To call from CLI php create_object_sql_from_table.php instance_path table_name

Parameters
$instance_path : string

path to the instance

$table_name : string

table's name

$CLI : mixed = false
Return values
string —

error or success message

missing_association_indexes()

Association columns that are not the leading column of any index, in the current database.

missing_association_indexes(mixed $DB) : array<string|int, mixed>
Parameters
$DB : mixed
Return values
array<string|int, mixed> —

list of ['TABLE_NAME' => ..., 'COLUMN_NAME' => ..., 'COLUMN_TYPE' => ...]

block_definition_is_valid()

Checks that the field definitions of a block declaration are themselves valid JSON.

block_definition_is_valid(string $declaration) : bool

A block file (<Nom>.json) holds, in its block_data entry, a json field whose value is the list of the block's editor fields. That value is a JSON string stored inside JSON: escaping it one level too deep produces a file that reads fine as a whole but installs a block_data row whose json column cannot be decoded, so the editor builds an empty form.

Parameters
$declaration : string

content of the block's json file

Return values
bool

install_blocks()

install_blocks(mixed $instance_path) : mixed
Parameters
$instance_path : mixed

install_instance()

install_instance(mixed $home_folder, mixed $admin_user, mixed $admin_pass, mixed $db_root_user, mixed $db_root_pass, mixed $db_root_user_central, mixed $db_root_password_central, mixed $db_root_user_slave, mixed $db_root_password_slave) : mixed
Parameters
$home_folder : mixed
$admin_user : mixed
$admin_pass : mixed
$db_root_user : mixed
$db_root_pass : mixed
$db_root_user_central : mixed
$db_root_password_central : mixed
$db_root_user_slave : mixed
$db_root_password_slave : mixed

install_module()

Install a module in the instance and add a menu in admin hierarchy

install_module(mixed $instance_path, mixed $module_name[, bool $ignore_file_and_folder = false ]) : string

The module is read from the toolkit's modules/ folder, or from the instance itself when the instance carries it (a folder under its admin or public folder holding the class, install.php and db.json).

To call from CLI : php install_module.php /path/to/my/instance/ module_name

Parameters
$instance_path : mixed
$module_name : mixed
$ignore_file_and_folder : bool = false
Return values
string —

error or success message

super_copy()

super_copy(mixed $source, mixed $target, mixed $user, mixed $groupe) : mixed
Parameters
$source : mixed
$target : mixed
$user : mixed
$groupe : mixed

super_mkdir()

super_mkdir(mixed $target, mixed $right, mixed $user, mixed $groupe) : mixed
Parameters
$target : mixed
$right : mixed
$user : mixed
$groupe : mixed

job_manager()

here is our buddy the job manager, made to be run as a command an working with "jobs" database as a job pile.

job_manager(mixed $argv) : mixed

arguments : -k , key to identify the job -C , callback when command is done -c , the command to execute -t , path to the instance -a , action for the job manager (new, progress or cancel)

exemples :

  • add a job : $job_manager_call='php /home/helphp/utils/job_manager.php -a"new" -t"'.$target.'" -c"'.$cmd.'" -C"'.$callback.'" -k"'.$key.'"';

  • get progress : $job_manager_call='php /home/helphp/utils/job_manager.php -a"progress" -t"'.$target.'" -k"'.$key.'"';

  • cancel : $job_manager_call='php /home/helphp/utils/job_manager.php -a"cancel" -t"'.$target.'" -k"'.$key.'"';

must be followed by : exec($job_manager_call);

Parameters
$argv : mixed

new_job()

to add a new job in "jobs" database pile

new_job(mixed $target, mixed $command, mixed $callback, mixed $key) : void
Parameters
$target : mixed

origine identifier

$command : mixed

to exec

$callback : mixed

ta call back after exec

$key : mixed

the key identifier that permit to follow th process.

cancel_job()

Cancel a job and move if from db to history

cancel_job(mixed $target, mixed $key) : void
Parameters
$target : mixed

origine identifier

$key : mixed

indentifier of the job to cancel.

set_status_job()

Change the status of a job in the pile.

set_status_job(mixed $target, mixed $key, mixed $status) : void
Parameters
$target : mixed

origine identifier

$key : mixed

indentifier of the job

$status : mixed

possible values :

  • 0 undone
  • 1 in progress
  • 2 done
  • 3 error

get_job_progress()

Get the progression of a job

get_job_progress(mixed $target, mixed $key) : string
Parameters
$target : mixed

origine identifier

$key : mixed

indentifier of the job

Return values
string —

messages / echo from the process if it got status = 1 (1 in progress)

  • status 0 : it will return "wait"
  • status 2 : "ok!" because finished
  • status 3 : "err" an error happenned.

job_loop()

The job loop will run until there is no more job to do, so it must be started at start of the server and it will go on infine loop waiting for job to execute.

job_loop() : void

mcp_server()

mcp_server(mixed $argv) : mixed
Parameters
$argv : mixed

minify()

Minify an instance : Take all js files to create only one js.gz file the same for the CSS theme.

minify(string $target) : string|files

At the end you'll get only two small files instead of 30/40~ and with a size reduced by ten. of course the impact on speed is huge and as the number or http queries is reduced the server ressource are increased by 20 ~ !

After minifying, you just need to swith DEVMODE to false in your main config file to see the difference.

it's common practices to keep one version of the instance as a dev version and the second as production.

in that case you just need to move css/gz/* and jsgz/* files from dev version to prod + database

Parameters
$target : string

the home path of the instance to get config

Return values
string|files —

echoing results of minification.

writeUTF8File()

writeUTF8File(mixed $filename, mixed $content) : mixed
Parameters
$filename : mixed
$content : mixed

process_launcher()

launch process in background and store their progress in redis, it's a subprocess script for helPHP\libs\utils\system_process_with_tracking

process_launcher(array<string|int, mixed> $argv) : mixed

must be launch from cli with arguments

can be used also to "force cancel" a job when type of process is "job", it's a special case when we want to create easily some "cancel" button for job in progress

Parameters
$argv : array<string|int, mixed>

the arguments of the cli command : argument Options: -k , the key to identify the process in redis -t , the type of the process -a , params depending the type -l , list of files that need to be locked during the process -i , path to the instance

Tags
see
system_process_with_tracking

rules_signature()

Signature of the rules of one source, to tell whether two sources carry the same CSS.

rules_signature(mixed $DB, string $t_rules, int $id_source) : array<string|int, mixed>
Parameters
$DB : mixed
$t_rules : string
$id_source : int
Return values
array<string|int, mixed>

count_rows()

count_rows(mixed $DB, string $table, int $id_source) : mixed
Parameters
$DB : mixed
$table : string
$id_source : int

duplicate_groups()

Duplicated sources, grouped by their identity.

duplicate_groups(mixed $DB, string $t_source) : array<string|int, mixed>

A block and a document are one source per (type, admin), whatever their path says: the pair is the identity, the path only says where the file is. A module and a theme are one source per file, so the path completes the identity.

Parameters
$DB : mixed
$t_source : string
Return values
array<string|int, mixed> —

One entry per group: type, admin, ids (comma separated), nb, and path for a module or a theme.

Restore all the symlinks for an instance, start with the external JS one and then process every module installed

restore_symlink(mixed $instance_path) : string

To call from CLI : php restore_symlink.php /path/to/my/instance/

Parameters
$instance_path : mixed
Return values
string —

error or success message

is_camel_case()

is_camel_case(string $name) : bool
Parameters
$name : string
Return values
bool

to_snake_case()

to_snake_case(string $name) : string
Parameters
$name : string
Return values
string

bare_name()

bare_name(string $kind, string $display) : string
Parameters
$kind : string
$display : string
Return values
string

check_file()

check_file(string $path) : array<string|int, mixed>
Parameters
$path : string
Return values
array<string|int, mixed>

apply_renames()

apply_renames(string $content, array<string|int, mixed> $renames) : string
Parameters
$content : string
$renames : array<string|int, mixed>
Return values
string

interactive_rename()

interactive_rename(string $file, array<string|int, mixed> $violations[, bool $auto = false ]) : void
Parameters
$file : string
$violations : array<string|int, mixed>
$auto : bool = false

uninstall_module()

Uninstall a module in the instance and

uninstall_module(mixed $instance_path, mixed $module_name[, bool $ignore_file_and_folder = false ][, mixed $CLI = false ]) : string

To call from CLI : php uninstall_module.php /path/to/my/instance/ module_name

Parameters
$instance_path : mixed
$module_name : mixed
$ignore_file_and_folder : bool = false
$CLI : mixed = false
Return values
string —

error or success message

helphp_ws_say()

helphp_ws_say(mixed $status, mixed $text) : mixed
Parameters
$status : mixed
$text : mixed

helphp_ws_fail()

helphp_ws_fail(mixed $text) : mixed
Parameters
$text : mixed

helphp_ws_config_value()

Reads a constant value out of a config file, without including it (the class may already be loaded with older values).

helphp_ws_config_value(string $file, string $name) : array<string|int, mixed>
Parameters
$file : string
$name : string
Return values
array<string|int, mixed> —

[found, raw value]

helphp_ws_config_ensure()

Adds the constants a previous installer did not know, before the closing brace.

helphp_ws_config_ensure(string $file, array<string, string> $lines) : int

Utils::write_in_config() replaces an existing const NAME = …; line but never creates one: an instance configured before IDLE_STOP existed would keep a config the runner reads with defaults, and the file would lie about it.

Parameters
$file : string

Config file.

$lines : array<string, string>

Constant name => value, already rendered.

Return values
int —

Number of lines added.

helphp_ws_send()

Sends one masked text frame, as a browser does.

helphp_ws_send(resource $socket, string $text) : void
Parameters
$socket : resource
$text : string

helphp_ws_read()

Reads one frame, answering pings on the way. Returns [opcode, payload].

helphp_ws_read(resource $socket) : array<string|int, mixed>|null
Parameters
$socket : resource
Return values
array<string|int, mixed>|null —

Null when the socket is closed or silent.

helphp_ws_probe()

End-to-end check: a real socket subscribes, a real publish is delivered.

helphp_ws_probe(string $instance) : int
Parameters
$instance : string
Return values
int —

0 when the chain works.

On this page

Search results