1 |
commit: b363dda0a3d3bdab2874b3f12c64c9fc8beeef4c |
2 |
Author: Michael Orlitzky <mjo <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Dec 19 23:29:40 2015 +0000 |
4 |
Commit: Michael Orlitzky <mjo <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Dec 19 23:29:40 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/eselect-php.git/commit/?id=b363dda0 |
7 |
|
8 |
Factor our the active SAPI target getter functions. |
9 |
|
10 |
We had five functions doing essentially the same thing: |
11 |
|
12 |
1. get_active_cli() |
13 |
2. get_active_cgi() |
14 |
3. get_active_fpm() |
15 |
4. get_active_phpdbg() |
16 |
5. get_active_apache2() |
17 |
|
18 |
Now that we have the sapi_active_link_path() function taking a SAPI |
19 |
name as an argument, these have been refactored. One new function |
20 |
get_sapi_active_target() takes a SAPI name as an argument and returns |
21 |
the name of the active target (using sapi_active_link_path). |
22 |
|
23 |
src/php.eselect.in | 62 +++++++++++++++--------------------------------------- |
24 |
1 file changed, 17 insertions(+), 45 deletions(-) |
25 |
|
26 |
diff --git a/src/php.eselect.in b/src/php.eselect.in |
27 |
index 6c1f803..fff7784 100644 |
28 |
--- a/src/php.eselect.in |
29 |
+++ b/src/php.eselect.in |
30 |
@@ -195,33 +195,6 @@ find_targets_phpdbg() { |
31 |
done | @SORT@ | @UNIQ@ |
32 |
} |
33 |
|
34 |
-get_active_cli() { |
35 |
- # See get_active_apache2() for an explanation of the sed call. |
36 |
- local target=$(canonicalise "$(sapi_active_link_path cli)") |
37 |
- local ver="s:.*/usr/.*/\(php[0-9]\.[0-9][0-9]*\)/bin/php:\1:p" |
38 |
- [[ -a "${target}" ]] && echo "${target}" | @SED@ -ne "${ver}" |
39 |
-} |
40 |
- |
41 |
-get_active_cgi() { |
42 |
- # See get_active_apache2() for an explanation of the sed call. |
43 |
- local target=$(canonicalise "$(sapi_active_link_path cgi)") |
44 |
- local ver="s:.*/usr/.*/\(php[0-9]\.[0-9][0-9]*\)/bin/php-cgi:\1:p" |
45 |
- [[ -a "${target}" ]] && echo "${target}" | @SED@ -ne "${ver}" |
46 |
-} |
47 |
- |
48 |
-get_active_fpm() { |
49 |
- # See get_active_apache2() for an explanation of the sed call. |
50 |
- local target=$(canonicalise "$(sapi_active_link_path fpm)") |
51 |
- local ver="s:.*/usr/.*/\(php[0-9]\.[0-9][0-9]*\)/bin/php-fpm:\1:p" |
52 |
- [[ -a "${target}" ]] && echo "${target}" | @SED@ -ne "${ver}" |
53 |
-} |
54 |
- |
55 |
-get_active_phpdbg() { |
56 |
- # See get_active_apache2() for an explanation of the sed call. |
57 |
- local target=$(canonicalise "$(sapi_active_link_path dbg)") |
58 |
- local ver="s:.*/usr/.*/\(php[0-9]\.[0-9][0-9]*\)/bin/phpdbg:\1:p" |
59 |
- [[ -a "${target}" ]] && echo "${target}" | @SED@ -ne "${ver}" |
60 |
-} |
61 |
|
62 |
# Find the active (selected) version of the apache2 module. Used to |
63 |
# decorate the output of the `eselect php list apache2` command. |
64 |
@@ -235,21 +208,20 @@ get_active_phpdbg() { |
65 |
# The "display name" of the active apache2 module. For example, |
66 |
# "php5.6" or "php7.0". |
67 |
# |
68 |
-get_active_apache2() { |
69 |
- local active_symlink target ver |
70 |
- |
71 |
- # The symlink to our active module. |
72 |
- active_symlink="$(sapi_active_link_path apache2)" |
73 |
- |
74 |
- # This sed expression finds the "display name" of the PHP version |
75 |
- # corresponding to a copy of libphp. For example, it parses the |
76 |
- # string "php5.6" out of "/usr/lib64/php5.6/apache2/libphp5.so". |
77 |
- ver="s:.*/usr/.*/\(php[0-9]\.[0-9]\)/apache2/libphp[57].so:\1:p" |
78 |
+get_sapi_active_target() { |
79 |
+ local sapi="${1}" |
80 |
+ local active_symlink=$(sapi_active_link_path "${sapi}") |
81 |
|
82 |
if [[ -L "${active_symlink}" ]] ; then |
83 |
- target=$(canonicalise "${active_symlink}") |
84 |
- if [[ -a "${target}" ]] ; then |
85 |
- echo "${target}" | @SED@ -ne "${ver}" |
86 |
+ local active_file=$(canonicalise "${active_symlink}") |
87 |
+ if [[ -a "${active_file}" ]] ; then |
88 |
+ # This sed command (regular expression) finds a target name |
89 |
+ # contained in a filesystem path. For example, it parses |
90 |
+ # "php5.6" from "/usr/lib64/php5.6/apache2/libphp5.so". |
91 |
+ # The curly braces are an attempt to avoid '+' which is |
92 |
+ # a GNU extension. |
93 |
+ local sed_cmd='s:.*/\(php[0-9]\.[0-9]\{1,\}\)/.*:\1:p' |
94 |
+ echo "${active_file}" | @SED@ -ne "${sed_cmd}" |
95 |
fi |
96 |
fi |
97 |
} |
98 |
@@ -305,7 +277,7 @@ list_apache2() { |
99 |
local targets |
100 |
local a |
101 |
targets=( $(find_targets_apache2) ) |
102 |
- a=$(get_active_apache2) |
103 |
+ a=$(get_sapi_active_target apache2) |
104 |
for (( i = 0; i < ${#targets[@]}; i++ )) ; do |
105 |
if [[ $a == ${targets[i]} ]] ; then |
106 |
targets[i]=$(highlight_marker "${targets[i]}") |
107 |
@@ -318,7 +290,7 @@ list_cli() { |
108 |
local targets |
109 |
local a |
110 |
targets=( $(find_targets_cli) ) |
111 |
- a=$(get_active_cli) |
112 |
+ a=$(get_sapi_active_target cli) |
113 |
for (( i = 0; i < ${#targets[@]}; i++ )) ; do |
114 |
if [[ $a == ${targets[i]} ]] ; then |
115 |
targets[i]=$(highlight_marker "${targets[i]}") |
116 |
@@ -331,7 +303,7 @@ list_cgi() { |
117 |
local targets |
118 |
local a |
119 |
targets=( $(find_targets_cgi) ) |
120 |
- a=$(get_active_cgi) |
121 |
+ a=$(get_sapi_active_target cgi) |
122 |
for (( i = 0; i < ${#targets[@]}; i++ )) ; do |
123 |
if [[ $a == ${targets[i]} ]] ; then |
124 |
targets[i]=$(highlight_marker "${targets[i]}") |
125 |
@@ -344,7 +316,7 @@ list_fpm() { |
126 |
local targets |
127 |
local a |
128 |
targets=( $(find_targets_fpm) ) |
129 |
- a=$(get_active_fpm) |
130 |
+ a=$(get_sapi_active_target fpm) |
131 |
for (( i = 0; i < ${#targets[@]}; i++ )) ; do |
132 |
if [[ $a == ${targets[i]} ]] ; then |
133 |
targets[i]=$(highlight_marker "${targets[i]}") |
134 |
@@ -357,7 +329,7 @@ list_phpdbg() { |
135 |
local targets |
136 |
local a |
137 |
targets=( $(find_targets_phpdbg) ) |
138 |
- a=$(get_active_phpdbg) |
139 |
+ a=$(get_sapi_active_target dbg) |
140 |
for (( i = 0; i < ${#targets[@]}; i++ )) ; do |
141 |
if [[ $a == ${targets[i]} ]] ; then |
142 |
targets[i]=$(highlight_marker "${targets[i]}") |