Interpreter for calling myVesta PHP functions

This commit is contained in:
myvesta 2023-03-26 03:40:33 +02:00 committed by GitHub
parent d84a021354
commit 09dcc123be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 95 additions and 6 deletions

View file

@ -0,0 +1,21 @@
<?php
if (!isset($argv)) exit;
include ("/usr/local/vesta/func/main.php");
include ("/usr/local/vesta/func/string.php");
$counter=count($argv);
if ($counter<1) myvesta_throw_error(2, 'Function is missing');
$func="myvesta_".$argv[1];
if (!function_exists($func)) myvesta_throw_error(2, 'Function does not exists');
$params=array();
for ($i=2; $i<$counter; $i++) {
$argv[$i]=myvesta_fix_backslashes($argv[$i]);
$params[]=$argv[$i];
}
// echo $func."\n"; print_r($params);
$r=call_user_func_array($func, $params);

View file

@ -28,7 +28,7 @@ function myvesta_check_args ($requried_arguments, $arguments) {
$argument_counter=count($argv);
$argument_counter--;
$argv[0]=str_replace('/usr/local/vesta/bin/', '', $argv[0]);
echo "-------------------- ".$argv[0]." --------------------\n";
// echo "-------------------- ".$argv[0]." --------------------\n";
if ($argument_counter<$requried_arguments) {
$arguments=str_replace(" ", "' '", $arguments);
$arguments="'".$arguments."'";
@ -42,8 +42,25 @@ function myvesta_check_args ($requried_arguments, $arguments) {
}
}
function myvesta_fix_args() {
global $argv;
$i=0;
foreach ($argv as $argument) {
if ($i==0) {$i++; continue;}
$argv[$i]=myvesta_fix_backslashes($argv[$i]);
$i++;
}
}
function myvesta_exit($code) {
global $argv;
echo "==================== ".$argv[0].": ".$code." ====================\n";
// echo "==================== ".$argv[0].": ".$code." ====================\n";
exit($code);
}
function myvesta_test_func () {
$args=func_get_args();
echo "You said: ";
print_r ($args);
echo "\n";
}

View file

@ -1,6 +1,8 @@
<?php
function myvesta_replace_in_file($find, $replace, $file) {
// --- file functions ---
function myvesta_replace_in_file($file, $find, $replace) {
if (!file_exists($file)) return myvesta_throw_error (MYVESTA_ERROR_FILE_DOES_NOT_EXISTS, "File '$file' not found");
$buf=file_get_contents($file);
@ -12,8 +14,47 @@ function myvesta_replace_in_file($find, $replace, $file) {
return $r;
}
function myvesta_str_get_between (&$text, $left_substring, $right_substring, $start=0, $return_left_substring=0, $return_right_substring=0, $left_substring_necessary=1, $right_substring_necessary=1)
{
function myvesta_get_between_in_file($file, $left_substring, $right_substring, $start=0, $return_left_substring=0, $return_right_substring=0, $left_substring_necessary=1, $right_substring_necessary=1) {
if (!file_exists($file)) return myvesta_throw_error (MYVESTA_ERROR_FILE_DOES_NOT_EXISTS, "File '$file' not found");
$text=file_get_contents($file);
return myvesta_str_get_between ($text, $left_substring, $right_substring, $start, $return_left_substring, $return_right_substring, $left_substring_necessary, $right_substring_necessary);
}
function myvesta_replace_in_file_once_between_including_borders($file, $left, $right, $replace_with) {
if (!file_exists($file)) return myvesta_throw_error (MYVESTA_ERROR_FILE_DOES_NOT_EXISTS, "File '$file' not found");
$text=file_get_contents($file);
$buf=myvesta_str_replace_once_between_including_borders($text, $left, $right, $replace_with);
$r=file_put_contents($file, $buf);
return $r;
}
function myvesta_strip_once_in_file_between_including_borders($file, $left, $right) {
if (!file_exists($file)) return myvesta_throw_error (MYVESTA_ERROR_FILE_DOES_NOT_EXISTS, "File '$file' not found");
$text=file_get_contents($file);
$buf=myvesta_str_strip_once_between_including_borders($text, $left, $right);
$r=file_put_contents($file, $buf);
return $r;
}
function myvesta_replace_in_file_between_including_borders($file, $left, $right, $replace_with) {
if (!file_exists($file)) return myvesta_throw_error (MYVESTA_ERROR_FILE_DOES_NOT_EXISTS, "File '$file' not found");
$text=file_get_contents($file);
$buf=myvesta_str_replace_between_including_borders($text, $left, $right, $replace_with);
$r=file_put_contents($file, $buf);
return $r;
}
function myvesta_strip_in_file_between_including_borders($file, $left, $right) {
if (!file_exists($file)) return myvesta_throw_error (MYVESTA_ERROR_FILE_DOES_NOT_EXISTS, "File '$file' not found");
$text=file_get_contents($file);
$buf=myvesta_str_strip_between_including_borders($text, $left, $right);
$r=file_put_contents($file, $buf);
return $r;
}
// --- string functions ---
function myvesta_str_get_between (&$text, $left_substring, $right_substring, $start=0, $return_left_substring=0, $return_right_substring=0, $left_substring_necessary=1, $right_substring_necessary=1) {
global $myvesta_str_found_at, $myvesta_str_end_at;
$myvesta_str_found_at=0;
$myvesta_str_end_at=0;
@ -64,7 +105,6 @@ function myvesta_str_strip_once_between_including_borders(&$text, $left, $right)
return substr($text, 0, $pos1).substr($text, $pos2+strlen($right));
}
function myvesta_str_replace_between_including_borders($text, $left, $right, $replace_with) {
$start=0;
$left_len=strlen($left);