commit: 7d9d9e7ef2a642c2f568de59b1af5f20a0c828ab Author: Michael Orlitzky <mjo <AT> gentoo <DOT> org> AuthorDate: Sat Dec 19 22:40:41 2015 +0000 Commit: Michael Orlitzky <mjo <AT> gentoo <DOT> org> CommitDate: Sat Dec 19 22:40:41 2015 +0000 URL: https://gitweb.gentoo.org/proj/eselect-php.git/commit/?id=7d9d9e7e
Factor out the target major version number parsing into a function. src/php.eselect.in | 32 +++++++++++++++++++++++++++----- 1 file 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