-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
ephp_lib_info.erl
96 lines (75 loc) · 2.29 KB
/
ephp_lib_info.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
-module(ephp_lib_info).
-author('manuel@altenwald.com').
-compile([warnings_as_errors]).
-include("ephp.hrl").
-export([
init_func/0,
init_config/0,
init_const/0,
phpinfo/2,
phpversion/2,
ini_get/3,
set_include_path/3
]).
-spec init_func() -> ephp_func:php_function_results().
init_func() -> [
phpinfo,
phpversion,
ini_get,
set_include_path
].
-spec init_config() -> ephp_func:php_config_results().
init_config() -> [].
-spec init_const() -> ephp_func:php_const_results().
init_const() -> [].
-spec phpinfo(context(), line()) -> undefined.
phpinfo(Context, _Line) ->
Version = ?PHP_VERSION,
Vsn = get_vsn(),
BuildDate = get_build_date(),
Release = list_to_binary(erlang:system_info(otp_release)),
PathPHPini = filename:dirname(?PHP_INI_FILE),
Directives = lists:foldl(fun
({_K,<<>>},R) -> R;
({K,V},R) when is_binary(K) ->
<<R/binary, K/binary, " => ", (ephp_data:to_bin(V))/binary, "\n">>;
(_,R) -> R
end, <<>>, application:get_all_env(ephp)),
Output = <<
"phpinfo()\n"
"PHP Version => ", Version/binary, "\n"
"\n"
"System => Erlang/OTP ", Release/binary, " ephp ", Vsn/binary, "\n"
"Build Date => ", BuildDate/binary, "\n"
"Configuration File (php.ini) Path => ", PathPHPini/binary, "\n"
"\n"
"Core\n"
"\n"
"PHP Version => ", Version/binary, "\n"
"\n"
"Directive => Value\n",
Directives/binary,
"\n"
>>,
ephp_context:set_output(Context, Output),
undefined.
-spec phpversion(context(), line()) -> binary().
phpversion(_Context, _Line) ->
?PHP_VERSION.
-spec ini_get(context(), line(), var_value()) -> mixed().
ini_get(_Context, _Line, {_,Key}) ->
ephp_config:get(Key).
-spec set_include_path(context(), line(), var_value()) -> binary().
set_include_path(_Context, _Line, {_,NewPath}) ->
ephp_config:set(<<"include_path">>, NewPath),
NewPath.
%% ----------------------------------------------------------------------------
%% Internal functions
%% ----------------------------------------------------------------------------
-spec get_vsn() -> binary().
get_vsn() ->
{ok, Vsn} = application:get_key(ephp, vsn),
list_to_binary(Vsn).
-spec get_build_date() -> binary().
get_build_date() ->
list_to_binary(?BUILD_DATE).