summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/php.eselect.in89
1 files changed, 77 insertions, 12 deletions
diff --git a/src/php.eselect.in b/src/php.eselect.in
index 72e6610..15792f3 100644
--- a/src/php.eselect.in
+++ b/src/php.eselect.in
@@ -8,13 +8,71 @@ MAINTAINER="php-bugs@gentoo.org"
MODULES="cli apache2 fpm cgi phpdbg"
+#
+# Output a list of link names (not full paths) belonging to the given
+# SAPI. These need to be updated when the user changes his active
+# target.
+#
+# INPUT:
+#
+# The name of a SAPI.
+#
+# OUTPUT:
+#
+# A space-separated list of link names belonging to the given
+# SAPI. For example, the "cli" SAPI has three link names: "php phpize
+# php-config". The "cgi" sapi has only "php-cgi".
+#
+sapi_active_link_names() {
+ local sapi="${1}"
+
+ case "${sapi}" in
+ apache2) echo "mod_php.so" ;;
+ cli) echo "php phpize php-config" ;;
+ fpm) echo "php-fpm" ;;
+ cgi) echo "php-cgi" ;;
+ dbg) echo "phpdbg" ;;
+ *) die "invalid SAPI name: ${sapi}" ;;
+ esac
+}
+
+
+# Each SAPI provides a few (one or more) "active" links in a
+# predictable location. And fortunately that location is fixed for a
+# given SAPI. For example, the "cgi" SAPI has its sole active symlink,
+# /usr/bin/php-cgi, in /usr/bin. Given a SAPI name, we return the
+# directory where that SAPI's links are located.
+#
+# INPUT:
+#
+# The name of a SAPI.
+#
+# OUTPUT:
+#
+# The directory in which the given SAPI's symlinks are located. For
+# example, the "cli" sapi has its three executable links in "/usr/bin".
+#
+sapi_active_link_dir() {
+ local sapi="${1}"
+ local bin_dir="${EROOT}/usr/bin"
+
+ case "${sapi}" in
+ apache2) echo "${EROOT}$(get_active_libdir)/apache2/modules" ;;
+ cli) echo "${bin_dir}" ;;
+ fpm) echo "${bin_dir}" ;;
+ cgi) echo "${bin_dir}" ;;
+ dbg) echo "${bin_dir}" ;;
+ *) die "invalid SAPI name: ${sapi}" ;;
+ esac
+}
+
# Each SAPI provides at least one "active" link in a predictable
# location. For example, the "cgi" SAPI has its active symlink at
# /usr/bin/php-cgi. Given a SAPI name we return the path to that link.
#
-# Note that the "cli" SAPI actually provides three executables -- we
-# return the path for only one. This is an API wart, not by design.
+# Note that SAPIs may provide more than one active link -- we return
+# the path for only the first.
#
# INPUT:
#
@@ -27,16 +85,11 @@ MODULES="cli apache2 fpm cgi phpdbg"
#
sapi_active_link_path() {
local sapi="${1}"
- local bin_dir="${EROOT}/usr/bin/"
- case "${sapi}" in
- apache2)
- echo "${EROOT}$(get_active_libdir)/apache2/modules/mod_php.so" ;;
- cli) echo "${bin_dir}/php" ;;
- fpm) echo "${bin_dir}/php-fpm" ;;
- cgi) echo "${bin_dir}/php-cgi" ;;
- dbg) echo "${bin_dir}/phpdbg" ;;
- *) die "invalid SAPI name: ${sapi}" ;;
- esac
+ local dir=$(sapi_active_link_dir "${sapi}")
+ local link_names=( $(sapi_active_link_names "${sapi}") )
+
+ # Use the first link name only.
+ echo "${dir}/${link_names[0]}"
}
@@ -319,6 +372,18 @@ list_phpdbg() {
list_sapi dbg
}
+
+set_sapi() {
+ local sapi="${1}"
+ local target="${2}"
+ local target_name=$(resolv_target "${sapi}" "${target}")
+ [[ -z $t ]] && die -q "invalid target ${target} for SAPI ${sapi}"
+
+ @LN_S@ --force "../..$(get_active_libdir)/${t}/bin/php-cgi" \
+ "$(sapi_active_link_path cgi)" || \
+ die -q "failed to create active php-cgi symlink"
+}
+
set_apache2() {
local active_symlink libdir major target=$(resolv_target apache2 $1)
active_symlink="$(sapi_active_link_path apache2)"