diff options
author | Michael Orlitzky <mjo@gentoo.org> | 2015-12-19 18:55:33 -0500 |
---|---|---|
committer | Michael Orlitzky <mjo@gentoo.org> | 2015-12-19 18:55:33 -0500 |
commit | 4f1ff31c738d4abe67849eb4280154889275127f (patch) | |
tree | 9573130420984dd73adff53ee8ae17e717496d7b | |
parent | Add some missing semicolons at the end of a case statement. (diff) | |
download | eselect-php-4f1ff31c738d4abe67849eb4280154889275127f.tar.gz eselect-php-4f1ff31c738d4abe67849eb4280154889275127f.tar.bz2 eselect-php-4f1ff31c738d4abe67849eb4280154889275127f.zip |
Add the find_sapi_targets() function and refactor.
The new function find_sapi_targets() takes a SAPI name as an argument
and outputs the valid targets for that SAPI. With it we replace the
following five functions that all did more or less the same thing:
1. find_targets_apache2()
2. find_targets_cli()
3. find_targets_fpm()
4. find_targets_cgi()
5. find_targets_phpdbg()
-rw-r--r-- | src/php.eselect.in | 82 |
1 files changed, 29 insertions, 53 deletions
diff --git a/src/php.eselect.in b/src/php.eselect.in index d9c1555..a377116 100644 --- a/src/php.eselect.in +++ b/src/php.eselect.in @@ -93,7 +93,7 @@ cleanup_sapi() { } update_sapi() { - local target=$(find_targets_$1 | tail -n 1) + local target=$(find_sapi_targets $1 | tail -n 1) local current=$(get_active_$1) [[ -z $target ]] && return 1 [[ $current = $target ]] && return 1 @@ -131,66 +131,42 @@ find_targets() { echo $dirs } -# List all valid apache2 targets. The list is obtained by searching -# for libphp*.so in locations determined by find_targets(). This list -# should therefore be a subset of find_targets(). +# List all valid targets for the given SAPI. The list is obtained by +# searching the filesystem for a particular (SAPI-specific) file in +# locations determined by find_targets(). This list should therefore +# be a subset of find_targets(). # # INPUT: # -# None. +# The name of a SAPI. # # OUTPUT: # -# The "display name" of every available apache PHP module, one per line. -# For example, +# The "display name" of every available target for this SAPI, one per +# line. For example, # # php5.6 # php7.0 # -find_targets_apache2() { - local libs target libdir - for target in $(find_targets); do - for libdir in $(get_libdirs); do - libs="${EROOT}${libdir}/${target}/apache2/libphp[57].so" - for lib in $libs; do - [[ -f "${lib}" ]] && echo $target - done - done - done | @SORT@ | @UNIQ@ -} - -find_targets_cli() { - local target libdir - for target in $(find_targets); do - for libdir in $(get_libdirs); do - [[ -f ${EROOT}${libdir}/$target/bin/php ]] && echo $target - done - done | @SORT@ | @UNIQ@ -} - -find_targets_fpm() { - local target libdir - for target in $(find_targets); do - for libdir in $(get_libdirs); do - [[ -f ${EROOT}${libdir}/$target/bin/php-fpm ]] && echo $target - done - done | @SORT@ | @UNIQ@ -} +find_sapi_targets() { + local sapi="${1}" -find_targets_cgi() { - local target libdir - for target in $(find_targets); do - for libdir in $(get_libdirs); do - [[ -f ${EROOT}${libdir}/$target/bin/php-cgi ]] && echo $target - done - done | @SORT@ | @UNIQ@ -} + local pattern_suffix + case "${sapi}" in + apache2) pattern_suffix="apache2/libphp[57].so" ;; + cli) pattern_suffix="bin/php" ;; + fpm) pattern_suffix="bin/php-fpm" ;; + cgi) pattern_suffix="bin/php-cgi" ;; + dbg) pattern_suffix="bin/phpdbg" ;; + *) die "invalid SAPI name: ${sapi}" ;; + esac -find_targets_phpdbg() { - local target libdir for target in $(find_targets); do for libdir in $(get_libdirs); do - [[ -f ${EROOT}${libdir}/$target/bin/phpdbg ]] && echo $target + local pattern="${EROOT}${libdir}/${target}/${pattern_suffix}" + for file in $pattern; do + [[ -f "${file}" ]] && echo "${target}" + done done done | @SORT@ | @UNIQ@ } @@ -256,7 +232,7 @@ write_mod_php_conf() { } resolv_target() { - local targets=( $(find_targets_$1) ) + local targets=( $(find_targets $1) ) if is_number $2; then if [[ $2 -le ${#targets[@]} && $2 -gt 0 ]] ; then echo "${targets[ $(( $2 - 1 )) ]}" @@ -276,7 +252,7 @@ check_module() { list_apache2() { local targets local a - targets=( $(find_targets_apache2) ) + targets=( $(find_sapi_targets apache2) ) a=$(get_sapi_active_target apache2) for (( i = 0; i < ${#targets[@]}; i++ )) ; do if [[ $a == ${targets[i]} ]] ; then @@ -289,7 +265,7 @@ list_apache2() { list_cli() { local targets local a - targets=( $(find_targets_cli) ) + targets=( $(find_sapi_targets cli) ) a=$(get_sapi_active_target cli) for (( i = 0; i < ${#targets[@]}; i++ )) ; do if [[ $a == ${targets[i]} ]] ; then @@ -302,7 +278,7 @@ list_cli() { list_cgi() { local targets local a - targets=( $(find_targets_cgi) ) + targets=( $(find_sapi_targets cgi) ) a=$(get_sapi_active_target cgi) for (( i = 0; i < ${#targets[@]}; i++ )) ; do if [[ $a == ${targets[i]} ]] ; then @@ -315,7 +291,7 @@ list_cgi() { list_fpm() { local targets local a - targets=( $(find_targets_fpm) ) + targets=( $(find_sapi_targets fpm) ) a=$(get_sapi_active_target fpm) for (( i = 0; i < ${#targets[@]}; i++ )) ; do if [[ $a == ${targets[i]} ]] ; then @@ -328,7 +304,7 @@ list_fpm() { list_phpdbg() { local targets local a - targets=( $(find_targets_phpdbg) ) + targets=( $(find_sapi_targets dbg) ) a=$(get_sapi_active_target dbg) for (( i = 0; i < ${#targets[@]}; i++ )) ; do if [[ $a == ${targets[i]} ]] ; then |