Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Appmonitor CLI client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
Appmonitor CLI client
Commits
07d35d1c
Commit
07d35d1c
authored
2 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
add colors
parent
23e6150a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inc_functions.php
+25
-147
25 additions, 147 deletions
inc_functions.php
with
25 additions
and
147 deletions
inc_functions.php
+
25
−
147
View file @
07d35d1c
...
@@ -3,9 +3,27 @@
...
@@ -3,9 +3,27 @@
// SHARED FUNCTIONS FOR INSTALLER AND BUILDER
// SHARED FUNCTIONS FOR INSTALLER AND BUILDER
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
$aCol
=
[
"reset"
=>
"
\e
[0m"
,
"red"
=>
"
\e
[31m"
,
"green"
=>
"
\e
[32m"
,
"yellow"
=>
"
\e
[33m"
,
"blue"
=>
"
\e
[34m"
,
"magenta"
=>
"
\e
[35m"
,
"cyan"
=>
"
\e
[36m"
,
"light_gray"
=>
"
\e
[37m"
,
"dark_gray"
=>
"
\e
[90m"
,
"light_red"
=>
"
\e
[91m"
,
"light_green"
=>
"
\e
[92m"
,
"light_yellow"
=>
"
\e
[93m"
,
"light_blue"
=>
"
\e
[94m"
,
"light_magenta"
=>
"
\e
[95m"
,
];
function
_h1
(
$s
):
void
function
_h1
(
$s
):
void
{
{
echo
"
\n
>>>>>>>>>>
$s
\n
"
;
global
$aCol
;
echo
"
\n
$aCol[magenta]
>>>>>>>>>>
$s$aCol[reset]
\n
"
;
/*
/*
echo "\n __".str_repeat("_", strlen($s))."\n";
echo "\n __".str_repeat("_", strlen($s))."\n";
...
@@ -16,7 +34,8 @@ function _h1($s): void
...
@@ -16,7 +34,8 @@ function _h1($s): void
}
}
function
_abort
(
$sMessage
,
$iExitcode
=
1
):
never
function
_abort
(
$sMessage
,
$iExitcode
=
1
):
never
{
{
echo
"❌
$sMessage
.
\n
"
;
global
$aCol
;
echo
"❌
$aCol[red]$sMessage.$aCol[reset]
\n
"
;
exit
(
$iExitcode
);
exit
(
$iExitcode
);
}
}
...
@@ -31,11 +50,12 @@ function _skip(string $sMessage=""): void
...
@@ -31,11 +50,12 @@ function _skip(string $sMessage=""): void
function
_chdir
(
$sDir
):
void
function
_chdir
(
$sDir
):
void
{
{
global
$aCol
;
if
(
!
is_dir
(
$sDir
))
{
if
(
!
is_dir
(
$sDir
))
{
_abort
(
"Directory '
$sDir
' not found."
);
_abort
(
"Directory '
$sDir
' not found."
);
}
}
chdir
(
$sDir
);
chdir
(
$sDir
);
echo
"dir # "
.
getcwd
()
.
"
\n
"
;
echo
"
$aCol[cyan]
dir # "
.
getcwd
()
.
"
$aCol[reset]
\n
"
;
}
}
/**
/**
...
@@ -45,7 +65,8 @@ function _chdir($sDir): void
...
@@ -45,7 +65,8 @@ function _chdir($sDir): void
*/
*/
function
_exec
(
$cmd
):
void
function
_exec
(
$cmd
):
void
{
{
echo
"cmd >
$cmd
\n
"
;
global
$aCol
;
echo
"
$aCol[blue]
cmd >
$cmd$aCol[reset]
\n
"
;
exec
(
"
$cmd
2>&1"
,
$aOut
,
$rc
);
exec
(
"
$cmd
2>&1"
,
$aOut
,
$rc
);
if
(
!
count
(
$aOut
))
{
if
(
!
count
(
$aOut
))
{
...
@@ -74,146 +95,3 @@ function _mkdir(string $sMyDir): void
...
@@ -74,146 +95,3 @@ function _mkdir(string $sMyDir): void
}
}
}
}
/**
* Compress PHP code
* from https://www.php.net/manual/de/function.php-strip-whitespace.php
* with removed lowercase function
*
* @param string $src source code or filename
* @return bool|string
*/
function
compress_php_src
(
string
$src
):
bool
|
string
{
// Whitespaces left and right from this signs can be ignored
static
$IW
=
array
(
T_CONCAT_EQUAL
,
// .=
T_DOUBLE_ARROW
,
// =>
T_BOOLEAN_AND
,
// &&
T_BOOLEAN_OR
,
// ||
T_IS_EQUAL
,
// ==
T_IS_NOT_EQUAL
,
// != or <>
T_IS_SMALLER_OR_EQUAL
,
// <=
T_IS_GREATER_OR_EQUAL
,
// >=
T_INC
,
// ++
T_DEC
,
// --
T_PLUS_EQUAL
,
// +=
T_MINUS_EQUAL
,
// -=
T_MUL_EQUAL
,
// *=
T_DIV_EQUAL
,
// /=
T_IS_IDENTICAL
,
// ===
T_IS_NOT_IDENTICAL
,
// !==
T_DOUBLE_COLON
,
// ::
T_PAAMAYIM_NEKUDOTAYIM
,
// ::
T_OBJECT_OPERATOR
,
// ->
T_DOLLAR_OPEN_CURLY_BRACES
,
// ${
T_AND_EQUAL
,
// &=
T_MOD_EQUAL
,
// %=
T_XOR_EQUAL
,
// ^=
T_OR_EQUAL
,
// |=
T_SL
,
// <<
T_SR
,
// >>
T_SL_EQUAL
,
// <<=
T_SR_EQUAL
,
// >>=
);
if
(
is_file
(
$src
))
{
if
(
!
$src
=
file_get_contents
(
$src
))
{
return
false
;
}
}
$tokens
=
token_get_all
(
$src
);
$new
=
""
;
$c
=
sizeof
(
$tokens
);
$iw
=
false
;
// ignore whitespace
$ih
=
false
;
// in HEREDOC
$ls
=
""
;
// last sign
$ot
=
null
;
// open tag
for
(
$i
=
0
;
$i
<
$c
;
$i
++
)
{
$token
=
$tokens
[
$i
];
if
(
is_array
(
$token
))
{
list
(
$tn
,
$ts
)
=
$token
;
// tokens: number, string, line
$tname
=
token_name
(
$tn
);
if
(
$tn
==
T_INLINE_HTML
)
{
$new
.
=
$ts
;
$iw
=
false
;
}
else
{
if
(
$tn
==
T_OPEN_TAG
)
{
if
(
strpos
(
$ts
,
" "
)
||
strpos
(
$ts
,
"
\n
"
)
||
strpos
(
$ts
,
"
\t
"
)
||
strpos
(
$ts
,
"
\r
"
))
{
$ts
=
rtrim
(
$ts
);
}
$ts
.
=
" "
;
$new
.
=
$ts
;
$ot
=
T_OPEN_TAG
;
$iw
=
true
;
}
elseif
(
$tn
==
T_OPEN_TAG_WITH_ECHO
)
{
$new
.
=
$ts
;
$ot
=
T_OPEN_TAG_WITH_ECHO
;
$iw
=
true
;
}
elseif
(
$tn
==
T_CLOSE_TAG
)
{
if
(
$ot
==
T_OPEN_TAG_WITH_ECHO
)
{
$new
=
rtrim
(
$new
,
"; "
);
}
else
{
$ts
=
" "
.
$ts
;
}
$new
.
=
$ts
;
$ot
=
null
;
$iw
=
false
;
}
elseif
(
in_array
(
$tn
,
$IW
))
{
$new
.
=
$ts
;
$iw
=
true
;
}
elseif
(
$tn
==
T_CONSTANT_ENCAPSED_STRING
||
$tn
==
T_ENCAPSED_AND_WHITESPACE
)
{
if
(
$ts
[
0
]
==
'"'
)
{
$ts
=
addcslashes
(
$ts
,
"
\n\t\r
"
);
}
$new
.
=
$ts
;
$iw
=
true
;
}
elseif
(
$tn
==
T_WHITESPACE
)
{
$nt
=
@
$tokens
[
$i
+
1
];
if
(
!
$iw
&&
(
!
is_string
(
$nt
)
||
$nt
==
'$'
)
&&
!
in_array
(
$nt
[
0
],
$IW
))
{
$new
.
=
" "
;
}
$iw
=
false
;
}
elseif
(
$tn
==
T_START_HEREDOC
)
{
$new
.
=
"<<<S
\n
"
;
$iw
=
false
;
$ih
=
true
;
// in HEREDOC
}
elseif
(
$tn
==
T_END_HEREDOC
)
{
$new
.
=
"S;"
;
$iw
=
true
;
$ih
=
false
;
// in HEREDOC
for
(
$j
=
$i
+
1
;
$j
<
$c
;
$j
++
)
{
if
(
is_string
(
$tokens
[
$j
])
&&
$tokens
[
$j
]
==
";"
)
{
$i
=
$j
;
break
;
}
else
if
(
$tokens
[
$j
][
0
]
==
T_CLOSE_TAG
)
{
break
;
}
}
}
elseif
(
$tn
==
T_COMMENT
||
$tn
==
T_DOC_COMMENT
)
{
$iw
=
true
;
}
else
{
/*
* Axel: DISABLE lowercase - it has bad impact on constants
*
if (!$ih) {
$ts = strtolower($ts);
}
*
*/
$new
.
=
$ts
;
$iw
=
false
;
}
}
$ls
=
""
;
}
else
{
if
((
$token
!=
";"
&&
$token
!=
":"
)
||
$ls
!=
$token
)
{
$new
.
=
$token
;
$ls
=
$token
;
}
$iw
=
true
;
}
}
return
$new
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment