diff options
author | Michael Orlitzky <mjo@gentoo.org> | 2015-12-19 17:40:41 -0500 |
---|---|---|
committer | Michael Orlitzky <mjo@gentoo.org> | 2015-12-19 17:40:41 -0500 |
commit | 7d9d9e7ef2a642c2f568de59b1af5f20a0c828ab (patch) | |
tree | 4864b0b3bc1e3385e6a4082df8ca522e08a936c5 /src | |
parent | Replace hard-coded SAPI executable link paths with a function call. (diff) | |
download | eselect-php-7d9d9e7ef2a642c2f568de59b1af5f20a0c828ab.tar.gz eselect-php-7d9d9e7ef2a642c2f568de59b1af5f20a0c828ab.tar.bz2 eselect-php-7d9d9e7ef2a642c2f568de59b1af5f20a0c828ab.zip |
Factor out the target major version number parsing into a function.
Diffstat (limited to 'src')
-rw-r--r-- | src/php.eselect.in | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/php.eselect.in b/src/php.eselect.in index 4af8650..0eb4ae4 100644 --- a/src/php.eselect.in +++ b/src/php.eselect.in @@ -40,6 +40,28 @@ sapi_active_bin_link_path() { esac } + +# Parse and return the major version from a target name. For example, +# the "php5.6" target has a major version of "5". +# +# INPUT: +# +# The name of a valid PHP target, like php5.6 or php7.0. +# +# OUTPUT: +# +# A major version number. An error is raised if the given target is +# not valid. +# +parse_target_major_version() { + local target="${1}" + local major="${target:3:1}" + case "${major}" in + 5|7) echo "${major}" ;; + *) die "invalid PHP target name: ${target}" + esac +} + cleanup_sapis() { local m local link @@ -273,9 +295,7 @@ write_mod_php_conf() { @MKDIR_P@ "${conf_dir}" || die "failed to create ${conf_dir}" - # Parse the major version (for example "5" or "7") out of the - # target name. - local major="${target:3:1}" + local major=$(parse_target_major_version "${target}") cat <<-EOF > "${conf_path}" || die "failed to write mod_php.conf" <IfModule !php${major}_module> LoadModule php${major}_module modules/mod_php.so @@ -367,15 +387,17 @@ list_phpdbg() { } set_apache2() { - local active_symlink libdir target=$(resolv_target apache2 $1) + local active_symlink libdir major target=$(resolv_target apache2 $1) active_symlink="$(get_apache2_active_symlink_path)" + major=$(parse_target_major_version "${target}") [[ -z $target ]] && die -q "invalid target" + for libdir in $(get_libdirs); do rm --force "${active_symlink}" || \ die "failed to remove active module symlink" - @LN_S@ --force "../../${target}/apache2/libphp${target:3:1}.so" \ + @LN_S@ --force "../../${target}/apache2/libphp${major}.so" \ "${active_symlink}" || \ die -q "failed to create active mod_php symlink" done |