Skip to content

Commit

Permalink
Adds support for PHP7, closes jippiGH-146
Browse files Browse the repository at this point in the history
Fixes non-overridable paths

Added validations and isolated fpm pool base dir

- Added validations for new path parameters
-
`$::php::fpm::pool::base_dir` is now mapped internally to another
variable, taking first the value of `$::php::fpm::pool::base_dir` when
provided, then inheriting from `$::php::fpm::config::pool_base_dir` when
the class `$::php::fpm::config` has been instantiated, and finally
inheriting from `$::php::params::fpm_pool_dir` if not provided and not
instantiated.

Change variable assignment logic

Replaces ternaries and fixes misbehaviour

Converts LFCR to LF and fixes test

Replacement of ternaries with pick_default
  • Loading branch information
Carlos García committed Dec 17, 2015
1 parent 03dac75 commit fe0a22f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 11 deletions.
9 changes: 6 additions & 3 deletions manifests/extension.pp
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,21 @@
}
}

$config_root_ini = pick_default($::php::config_root_ini, $::php::params::config_root_ini)
::php::config { $title:
file => "${::php::params::config_root_ini}/${lowercase_title}.ini",
file => "${config_root_ini}/${lowercase_title}.ini",
config => $final_settings,
}

# Ubuntu/Debian systems use the mods-available folder. We need to enable
# settings files ourselves with php5enmod command.
$ext_tool_enable = pick_default($::php::ext_tool_enable, $::php::params::ext_tool_enable)
$ext_tool_query = pick_default($::php::ext_tool_query, $::php::params::ext_tool_query)
if $::osfamily == 'Debian' {
$cmd = "/usr/sbin/php5enmod ${lowercase_title}"
$cmd = "${ext_tool_enable} ${lowercase_title}"

exec { $cmd:
unless => "/usr/sbin/php5query -s cli -m ${lowercase_title}",
unless => "${ext_tool_query} -s cli -m ${lowercase_title}",
require =>::Php::Config[$title],
}

Expand Down
15 changes: 13 additions & 2 deletions manifests/fpm/pool.pp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@
# [*php_directives*]
# List of custom directives that are appended to the pool config
#
# [*base_dir*]
# The folder that contains the php-fpm pool configs. This defaults to a
# sensible default depending on your operating system, like
# '/etc/php5/fpm/pool.d' or '/etc/php-fpm.d'
#
define php::fpm::pool (
$ensure = 'present',
$listen = '127.0.0.1:9000',
Expand Down Expand Up @@ -138,10 +143,15 @@
$php_admin_flag = {},
$php_directives = [],
$root_group = $::php::params::root_group,
$base_dir = undef,
) {

include ::php::params

if $base_dir != undef {
validate_absolute_path($base_dir)
}

$pool = $title

# Hack-ish to default to user for group too
Expand All @@ -154,13 +164,14 @@
default => $::php::fpm::package,
}

$pool_base_dir = pick_default($base_dir, $::php::fpm::config::pool_base_dir, $::php::params::fpm_pool_dir)
if ($ensure == 'absent') {
file { "${::php::params::fpm_pool_dir}/${pool}.conf":
file { "${pool_base_dir}/${pool}.conf":
ensure => absent,
notify => Class['::php::fpm::service'],
}
} else {
file { "${::php::params::fpm_pool_dir}/${pool}.conf":
file { "${pool_base_dir}/${pool}.conf":
ensure => file,
notify => Class['::php::fpm::service'],
require => Package[$real_package],
Expand Down
25 changes: 25 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@
# to a sensible default depending on your operating system, like 'php-' or
# 'php5-'.
#
# [*config_root_ini*]
# This is the path to the config .ini files of the extensions. This defaults
# to a sensible default depending on your operating system, like
# '/etc/php5/mods-available' or '/etc/php5/conf.d'.
#
# [*$ext_tool_enable*]
# Absolute path to php tool for enabling extensions in debian/ubuntu systems.
# This defaults to '/usr/sbin/php5enmod'.
#
# [*$ext_tool_query*]
# Absolute path to php tool for querying information about extensions in
# debian/ubuntu systems. This defaults to '/usr/sbin/php5query'.
#
class php (
$ensure = $::php::params::ensure,
$manage_repos = $::php::params::manage_repos,
Expand All @@ -46,6 +59,9 @@
$extensions = {},
$settings = {},
$package_prefix = $::php::params::package_prefix,
$config_root_ini = $::php::params::config_root_ini,
$ext_tool_enable = $::php::params::ext_tool_enable,
$ext_tool_query = $::php::params::ext_tool_query,
) inherits ::php::params {

validate_string($ensure)
Expand All @@ -59,6 +75,15 @@
validate_bool($phpunit)
validate_hash($extensions)
validate_hash($settings)
if $config_root_ini != undef {
validate_absolute_path($config_root_ini)
}
if $ext_tool_enable != undef {
validate_absolute_path($ext_tool_enable)
}
if $ext_tool_query != undef {
validate_absolute_path($ext_tool_query)
}

# Deep merge global php settings
$real_settings = deep_merge($settings, hiera_hash('php::settings', {}))
Expand Down
18 changes: 13 additions & 5 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# PHP params class
#
class php::params {
class php::params(
$cfg_root = undef,
) {

if $cfg_root != undef {
validate_absolute_path($cfg_root)
}

$ensure = 'present'
$fpm_service_enable = true
Expand All @@ -15,8 +21,8 @@

case $::osfamily {
'Debian': {
$config_root = '/etc/php5'
$config_root_ini = "${::php::params::config_root}/mods-available"
$config_root = pick($cfg_root, '/etc/php5')
$config_root_ini = "${config_root}/mods-available"
$common_package_names = []
$common_package_suffixes = ['cli', 'common']
$cli_inifile = "${config_root}/cli/php.ini"
Expand All @@ -35,6 +41,8 @@
$package_prefix = 'php5-'
$compiler_packages = 'build-essential'
$root_group = 'root'
$ext_tool_enable = '/usr/sbin/php5enmod'
$ext_tool_query = '/usr/sbin/php5query'

case $::operatingsystem {
'Debian': {
Expand All @@ -52,7 +60,7 @@
}

'Suse': {
$config_root = '/etc/php5'
$config_root = pick($cfg_root, '/etc/php5')
$config_root_ini = "${config_root}/conf.d"
$common_package_names = ['php5']
$common_package_suffixes = []
Expand Down Expand Up @@ -107,7 +115,7 @@
$root_group = 'root'
}
'FreeBSD': {
$config_root = '/usr/local/etc'
$config_root = pick($cfg_root, '/usr/local/etc')
$config_root_ini = "${config_root}/php"
# No common packages, because the required PHP base package will be
# pulled in as a dependency. This preserves the ability to choose
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@

it {
should contain_php__config('xdebug').with({
:file => '/etc/php5/mods-available/xdebug.ini',
:file => "#{etcdir}/xdebug.ini",
})
}
context 'pecl installation' do
Expand Down

0 comments on commit fe0a22f

Please sign in to comment.