mirror of
https://github.com/myvesta/vesta
synced 2025-07-05 20:41:53 -07:00
Interpreter for calling myVesta PHP functions
This commit is contained in:
parent
d84a021354
commit
09dcc123be
4 changed files with 95 additions and 6 deletions
11
bin/v-php-func
Normal file
11
bin/v-php-func
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# info: calling myVesta PHP functions
|
||||||
|
# options: FUNCTION
|
||||||
|
#
|
||||||
|
# The function is calling myVesta PHP functions.
|
||||||
|
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
# Action #
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
|
php /usr/local/vesta/func/bash-to-php-interpreter.php "$@"
|
21
func/bash-to-php-interpreter.php
Normal file
21
func/bash-to-php-interpreter.php
Normal 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);
|
|
@ -28,7 +28,7 @@ function myvesta_check_args ($requried_arguments, $arguments) {
|
||||||
$argument_counter=count($argv);
|
$argument_counter=count($argv);
|
||||||
$argument_counter--;
|
$argument_counter--;
|
||||||
$argv[0]=str_replace('/usr/local/vesta/bin/', '', $argv[0]);
|
$argv[0]=str_replace('/usr/local/vesta/bin/', '', $argv[0]);
|
||||||
echo "-------------------- ".$argv[0]." --------------------\n";
|
// echo "-------------------- ".$argv[0]." --------------------\n";
|
||||||
if ($argument_counter<$requried_arguments) {
|
if ($argument_counter<$requried_arguments) {
|
||||||
$arguments=str_replace(" ", "' '", $arguments);
|
$arguments=str_replace(" ", "' '", $arguments);
|
||||||
$arguments="'".$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) {
|
function myvesta_exit($code) {
|
||||||
global $argv;
|
global $argv;
|
||||||
echo "==================== ".$argv[0].": ".$code." ====================\n";
|
// echo "==================== ".$argv[0].": ".$code." ====================\n";
|
||||||
exit($code);
|
exit($code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function myvesta_test_func () {
|
||||||
|
$args=func_get_args();
|
||||||
|
echo "You said: ";
|
||||||
|
print_r ($args);
|
||||||
|
echo "\n";
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
<?php
|
<?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");
|
if (!file_exists($file)) return myvesta_throw_error (MYVESTA_ERROR_FILE_DOES_NOT_EXISTS, "File '$file' not found");
|
||||||
|
|
||||||
$buf=file_get_contents($file);
|
$buf=file_get_contents($file);
|
||||||
|
@ -12,8 +14,47 @@ function myvesta_replace_in_file($find, $replace, $file) {
|
||||||
return $r;
|
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;
|
global $myvesta_str_found_at, $myvesta_str_end_at;
|
||||||
$myvesta_str_found_at=0;
|
$myvesta_str_found_at=0;
|
||||||
$myvesta_str_end_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));
|
return substr($text, 0, $pos1).substr($text, $pos2+strlen($right));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function myvesta_str_replace_between_including_borders($text, $left, $right, $replace_with) {
|
function myvesta_str_replace_between_including_borders($text, $left, $right, $replace_with) {
|
||||||
$start=0;
|
$start=0;
|
||||||
$left_len=strlen($left);
|
$left_len=strlen($left);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue