summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Orlitzky <mjo@gentoo.org>2015-12-19 18:29:40 -0500
committerMichael Orlitzky <mjo@gentoo.org>2015-12-19 18:29:40 -0500
commitb363dda0a3d3bdab2874b3f12c64c9fc8beeef4c (patch)
tree7dba18f7450b8845de801a2e5b392594d7847d0b /src
parentGeneralize sapi_active_bin_link_path() to sapi_active_link_path(). (diff)
downloadeselect-php-b363dda0a3d3bdab2874b3f12c64c9fc8beeef4c.tar.gz
eselect-php-b363dda0a3d3bdab2874b3f12c64c9fc8beeef4c.tar.bz2
eselect-php-b363dda0a3d3bdab2874b3f12c64c9fc8beeef4c.zip
Factor our the active SAPI target getter functions.
We had five functions doing essentially the same thing: 1. get_active_cli() 2. get_active_cgi() 3. get_active_fpm() 4. get_active_phpdbg() 5. get_active_apache2() Now that we have the sapi_active_link_path() function taking a SAPI name as an argument, these have been refactored. One new function get_sapi_active_target() takes a SAPI name as an argument and returns the name of the active target (using sapi_active_link_path).
Diffstat (limited to 'src')
-rw-r--r--src/php.eselect.in62
1 files changed, 17 insertions, 45 deletions
diff --git a/src/php.eselect.in b/src/php.eselect.in
index 6c1f803..fff7784 100644
--- a/src/php.eselect.in
+++ b/src/php.eselect.in
@@ -195,33 +195,6 @@ find_targets_phpdbg() {
done | @SORT@ | @UNIQ@
}
-get_active_cli() {
- # See get_active_apache2() for an explanation of the sed call.
- local target=$(canonicalise "$(sapi_active_link_path cli)")
- local ver="s:.*/usr/.*/\(php[0-9]\.[0-9][0-9]*\)/bin/php:\1:p"
- [[ -a "${target}" ]] && echo "${target}" | @SED@ -ne "${ver}"
-}
-
-get_active_cgi() {
- # See get_active_apache2() for an explanation of the sed call.
- local target=$(canonicalise "$(sapi_active_link_path cgi)")
- local ver="s:.*/usr/.*/\(php[0-9]\.[0-9][0-9]*\)/bin/php-cgi:\1:p"
- [[ -a "${target}" ]] && echo "${target}" | @SED@ -ne "${ver}"
-}
-
-get_active_fpm() {
- # See get_active_apache2() for an explanation of the sed call.
- local target=$(canonicalise "$(sapi_active_link_path fpm)")
- local ver="s:.*/usr/.*/\(php[0-9]\.[0-9][0-9]*\)/bin/php-fpm:\1:p"
- [[ -a "${target}" ]] && echo "${target}" | @SED@ -ne "${ver}"
-}
-
-get_active_phpdbg() {
- # See get_active_apache2() for an explanation of the sed call.
- local target=$(canonicalise "$(sapi_active_link_path dbg)")
- local ver="s:.*/usr/.*/\(php[0-9]\.[0-9][0-9]*\)/bin/phpdbg:\1:p"
- [[ -a "${target}" ]] && echo "${target}" | @SED@ -ne "${ver}"
-}
# Find the active (selected) version of the apache2 module. Used to
# decorate the output of the `eselect php list apache2` command.
@@ -235,21 +208,20 @@ get_active_phpdbg() {
# The "display name" of the active apache2 module. For example,
# "php5.6" or "php7.0".
#
-get_active_apache2() {
- local active_symlink target ver
-
- # The symlink to our active module.
- active_symlink="$(sapi_active_link_path apache2)"
-
- # This sed expression finds the "display name" of the PHP version
- # corresponding to a copy of libphp. For example, it parses the
- # string "php5.6" out of "/usr/lib64/php5.6/apache2/libphp5.so".
- ver="s:.*/usr/.*/\(php[0-9]\.[0-9]\)/apache2/libphp[57].so:\1:p"
+get_sapi_active_target() {
+ local sapi="${1}"
+ local active_symlink=$(sapi_active_link_path "${sapi}")
if [[ -L "${active_symlink}" ]] ; then
- target=$(canonicalise "${active_symlink}")
- if [[ -a "${target}" ]] ; then
- echo "${target}" | @SED@ -ne "${ver}"
+ local active_file=$(canonicalise "${active_symlink}")
+ if [[ -a "${active_file}" ]] ; then
+ # This sed command (regular expression) finds a target name
+ # contained in a filesystem path. For example, it parses
+ # "php5.6" from "/usr/lib64/php5.6/apache2/libphp5.so".
+ # The curly braces are an attempt to avoid '+' which is
+ # a GNU extension.
+ local sed_cmd='s:.*/\(php[0-9]\.[0-9]\{1,\}\)/.*:\1:p'
+ echo "${active_file}" | @SED@ -ne "${sed_cmd}"
fi
fi
}
@@ -305,7 +277,7 @@ list_apache2() {
local targets
local a
targets=( $(find_targets_apache2) )
- a=$(get_active_apache2)
+ a=$(get_sapi_active_target apache2)
for (( i = 0; i < ${#targets[@]}; i++ )) ; do
if [[ $a == ${targets[i]} ]] ; then
targets[i]=$(highlight_marker "${targets[i]}")
@@ -318,7 +290,7 @@ list_cli() {
local targets
local a
targets=( $(find_targets_cli) )
- a=$(get_active_cli)
+ a=$(get_sapi_active_target cli)
for (( i = 0; i < ${#targets[@]}; i++ )) ; do
if [[ $a == ${targets[i]} ]] ; then
targets[i]=$(highlight_marker "${targets[i]}")
@@ -331,7 +303,7 @@ list_cgi() {
local targets
local a
targets=( $(find_targets_cgi) )
- a=$(get_active_cgi)
+ a=$(get_sapi_active_target cgi)
for (( i = 0; i < ${#targets[@]}; i++ )) ; do
if [[ $a == ${targets[i]} ]] ; then
targets[i]=$(highlight_marker "${targets[i]}")
@@ -344,7 +316,7 @@ list_fpm() {
local targets
local a
targets=( $(find_targets_fpm) )
- a=$(get_active_fpm)
+ a=$(get_sapi_active_target fpm)
for (( i = 0; i < ${#targets[@]}; i++ )) ; do
if [[ $a == ${targets[i]} ]] ; then
targets[i]=$(highlight_marker "${targets[i]}")
@@ -357,7 +329,7 @@ list_phpdbg() {
local targets
local a
targets=( $(find_targets_phpdbg) )
- a=$(get_active_phpdbg)
+ a=$(get_sapi_active_target dbg)
for (( i = 0; i < ${#targets[@]}; i++ )) ; do
if [[ $a == ${targets[i]} ]] ; then
targets[i]=$(highlight_marker "${targets[i]}")