1 |
commit: 4f1ff31c738d4abe67849eb4280154889275127f |
2 |
Author: Michael Orlitzky <mjo <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Dec 19 23:55:33 2015 +0000 |
4 |
Commit: Michael Orlitzky <mjo <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Dec 19 23:55:33 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/eselect-php.git/commit/?id=4f1ff31c |
7 |
|
8 |
Add the find_sapi_targets() function and refactor. |
9 |
|
10 |
The new function find_sapi_targets() takes a SAPI name as an argument |
11 |
and outputs the valid targets for that SAPI. With it we replace the |
12 |
following five functions that all did more or less the same thing: |
13 |
|
14 |
1. find_targets_apache2() |
15 |
2. find_targets_cli() |
16 |
3. find_targets_fpm() |
17 |
4. find_targets_cgi() |
18 |
5. find_targets_phpdbg() |
19 |
|
20 |
src/php.eselect.in | 82 +++++++++++++++++++----------------------------------- |
21 |
1 file changed, 29 insertions(+), 53 deletions(-) |
22 |
|
23 |
diff --git a/src/php.eselect.in b/src/php.eselect.in |
24 |
index d9c1555..a377116 100644 |
25 |
--- a/src/php.eselect.in |
26 |
+++ b/src/php.eselect.in |
27 |
@@ -93,7 +93,7 @@ cleanup_sapi() { |
28 |
} |
29 |
|
30 |
update_sapi() { |
31 |
- local target=$(find_targets_$1 | tail -n 1) |
32 |
+ local target=$(find_sapi_targets $1 | tail -n 1) |
33 |
local current=$(get_active_$1) |
34 |
[[ -z $target ]] && return 1 |
35 |
[[ $current = $target ]] && return 1 |
36 |
@@ -131,66 +131,42 @@ find_targets() { |
37 |
echo $dirs |
38 |
} |
39 |
|
40 |
-# List all valid apache2 targets. The list is obtained by searching |
41 |
-# for libphp*.so in locations determined by find_targets(). This list |
42 |
-# should therefore be a subset of find_targets(). |
43 |
+# List all valid targets for the given SAPI. The list is obtained by |
44 |
+# searching the filesystem for a particular (SAPI-specific) file in |
45 |
+# locations determined by find_targets(). This list should therefore |
46 |
+# be a subset of find_targets(). |
47 |
# |
48 |
# INPUT: |
49 |
# |
50 |
-# None. |
51 |
+# The name of a SAPI. |
52 |
# |
53 |
# OUTPUT: |
54 |
# |
55 |
-# The "display name" of every available apache PHP module, one per line. |
56 |
-# For example, |
57 |
+# The "display name" of every available target for this SAPI, one per |
58 |
+# line. For example, |
59 |
# |
60 |
# php5.6 |
61 |
# php7.0 |
62 |
# |
63 |
-find_targets_apache2() { |
64 |
- local libs target libdir |
65 |
- for target in $(find_targets); do |
66 |
- for libdir in $(get_libdirs); do |
67 |
- libs="${EROOT}${libdir}/${target}/apache2/libphp[57].so" |
68 |
- for lib in $libs; do |
69 |
- [[ -f "${lib}" ]] && echo $target |
70 |
- done |
71 |
- done |
72 |
- done | @SORT@ | @UNIQ@ |
73 |
-} |
74 |
- |
75 |
-find_targets_cli() { |
76 |
- local target libdir |
77 |
- for target in $(find_targets); do |
78 |
- for libdir in $(get_libdirs); do |
79 |
- [[ -f ${EROOT}${libdir}/$target/bin/php ]] && echo $target |
80 |
- done |
81 |
- done | @SORT@ | @UNIQ@ |
82 |
-} |
83 |
- |
84 |
-find_targets_fpm() { |
85 |
- local target libdir |
86 |
- for target in $(find_targets); do |
87 |
- for libdir in $(get_libdirs); do |
88 |
- [[ -f ${EROOT}${libdir}/$target/bin/php-fpm ]] && echo $target |
89 |
- done |
90 |
- done | @SORT@ | @UNIQ@ |
91 |
-} |
92 |
+find_sapi_targets() { |
93 |
+ local sapi="${1}" |
94 |
|
95 |
-find_targets_cgi() { |
96 |
- local target libdir |
97 |
- for target in $(find_targets); do |
98 |
- for libdir in $(get_libdirs); do |
99 |
- [[ -f ${EROOT}${libdir}/$target/bin/php-cgi ]] && echo $target |
100 |
- done |
101 |
- done | @SORT@ | @UNIQ@ |
102 |
-} |
103 |
+ local pattern_suffix |
104 |
+ case "${sapi}" in |
105 |
+ apache2) pattern_suffix="apache2/libphp[57].so" ;; |
106 |
+ cli) pattern_suffix="bin/php" ;; |
107 |
+ fpm) pattern_suffix="bin/php-fpm" ;; |
108 |
+ cgi) pattern_suffix="bin/php-cgi" ;; |
109 |
+ dbg) pattern_suffix="bin/phpdbg" ;; |
110 |
+ *) die "invalid SAPI name: ${sapi}" ;; |
111 |
+ esac |
112 |
|
113 |
-find_targets_phpdbg() { |
114 |
- local target libdir |
115 |
for target in $(find_targets); do |
116 |
for libdir in $(get_libdirs); do |
117 |
- [[ -f ${EROOT}${libdir}/$target/bin/phpdbg ]] && echo $target |
118 |
+ local pattern="${EROOT}${libdir}/${target}/${pattern_suffix}" |
119 |
+ for file in $pattern; do |
120 |
+ [[ -f "${file}" ]] && echo "${target}" |
121 |
+ done |
122 |
done |
123 |
done | @SORT@ | @UNIQ@ |
124 |
} |
125 |
@@ -256,7 +232,7 @@ write_mod_php_conf() { |
126 |
} |
127 |
|
128 |
resolv_target() { |
129 |
- local targets=( $(find_targets_$1) ) |
130 |
+ local targets=( $(find_targets $1) ) |
131 |
if is_number $2; then |
132 |
if [[ $2 -le ${#targets[@]} && $2 -gt 0 ]] ; then |
133 |
echo "${targets[ $(( $2 - 1 )) ]}" |
134 |
@@ -276,7 +252,7 @@ check_module() { |
135 |
list_apache2() { |
136 |
local targets |
137 |
local a |
138 |
- targets=( $(find_targets_apache2) ) |
139 |
+ targets=( $(find_sapi_targets apache2) ) |
140 |
a=$(get_sapi_active_target apache2) |
141 |
for (( i = 0; i < ${#targets[@]}; i++ )) ; do |
142 |
if [[ $a == ${targets[i]} ]] ; then |
143 |
@@ -289,7 +265,7 @@ list_apache2() { |
144 |
list_cli() { |
145 |
local targets |
146 |
local a |
147 |
- targets=( $(find_targets_cli) ) |
148 |
+ targets=( $(find_sapi_targets cli) ) |
149 |
a=$(get_sapi_active_target cli) |
150 |
for (( i = 0; i < ${#targets[@]}; i++ )) ; do |
151 |
if [[ $a == ${targets[i]} ]] ; then |
152 |
@@ -302,7 +278,7 @@ list_cli() { |
153 |
list_cgi() { |
154 |
local targets |
155 |
local a |
156 |
- targets=( $(find_targets_cgi) ) |
157 |
+ targets=( $(find_sapi_targets cgi) ) |
158 |
a=$(get_sapi_active_target cgi) |
159 |
for (( i = 0; i < ${#targets[@]}; i++ )) ; do |
160 |
if [[ $a == ${targets[i]} ]] ; then |
161 |
@@ -315,7 +291,7 @@ list_cgi() { |
162 |
list_fpm() { |
163 |
local targets |
164 |
local a |
165 |
- targets=( $(find_targets_fpm) ) |
166 |
+ targets=( $(find_sapi_targets fpm) ) |
167 |
a=$(get_sapi_active_target fpm) |
168 |
for (( i = 0; i < ${#targets[@]}; i++ )) ; do |
169 |
if [[ $a == ${targets[i]} ]] ; then |
170 |
@@ -328,7 +304,7 @@ list_fpm() { |
171 |
list_phpdbg() { |
172 |
local targets |
173 |
local a |
174 |
- targets=( $(find_targets_phpdbg) ) |
175 |
+ targets=( $(find_sapi_targets dbg) ) |
176 |
a=$(get_sapi_active_target dbg) |
177 |
for (( i = 0; i < ${#targets[@]}; i++ )) ; do |
178 |
if [[ $a == ${targets[i]} ]] ; then |