Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #40 from webflo/xhprof
Browse files Browse the repository at this point in the history
Add Xhprof extension.
  • Loading branch information
mattheath committed Jun 2, 2014
2 parents 8a4ed4e + 637fb9c commit 43833fd
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/puppet/provider/php_extension/pecl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
def create

# Let's get a few things straight
@work_dir = "#{@resource[:cache_dir]}/#{@resource[:package_name]}/#{@resource[:package_name]}"
unless @resource[:extension_dir].nil?
@work_dir = "#{@resource[:cache_dir]}/#{@resource[:package_name]}/#{@resource[:package_name]}/#{@resource[:extension_dir]}"
else
@work_dir = "#{@resource[:cache_dir]}/#{@resource[:package_name]}/#{@resource[:package_name]}"
end
@php_version_prefix = "#{@resource[:phpenv_root]}/versions/#{@resource[:php_version]}"
@resource[:compiled_name] ||= "#{@resource[:extension]}.so"

Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/php_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@
defaultto :pecl
end

# Some PECL modules have a different module layout and the php extension
# source in not in the root directory (e.g. xhprof)
newparam(:extension_dir) do
end

end
46 changes: 46 additions & 0 deletions manifests/extension/xhprof.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Installs a php extension for a specific version of php.
#
# Usage:
#
# php::extension::xhprof { 'xhprof for 5.4.10':
# php => '5.4.10',
# version => '0.9.4'
# }
#
define php::extension::xhprof(
$php,
$version = '0.9.4',
$config_template = 'php/extensions/xhprof.ini.erb'
) {
require php::config
# Require php version eg. php::5_4_10
# This will compile, install and set up config dirs if not present
require join(['php', join(split($php, '[.]'), '_')], '::')

$extension = 'xhprof'
$package_name = "xhprof-${version}"
$url = "http://pecl.php.net/get/xhprof-${version}.tgz"

# Final module install path
$module_path = "${php::config::root}/versions/${php}/modules/${extension}.so"

php_extension { $name:
extension => $extension,
version => $version,
package_name => $package_name,
package_url => $url,
homebrew_path => $boxen::config::homebrewdir,
phpenv_root => $php::config::root,
php_version => $php,
cache_dir => $php::config::extensioncachedir,
extension_dir => 'extension'
}

# Add config file once extension is installed

file { "${php::config::configdir}/${php}/conf.d/${extension}.ini":
content => template($config_template),
require => Php_extension[$name],
}

}
33 changes: 33 additions & 0 deletions spec/defines/extensions/php_extension_xhprof_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'spec_helper'

describe "php::extension::xhprof" do
let(:facts) { default_test_facts }
let(:title) { "xhprof for 5.4.17" }
let(:params) do
{
:php => "5.4.17",
:version => "0.9.4"
}
end

it do
should include_class("php::config")
should include_class("php::5_4_17")

should contain_php_extension("xhprof for 5.4.17").with({
:extension => "xhprof",
:version => "0.9.4",
:package_name => "xhprof-0.9.4",
:package_url => "http://pecl.php.net/get/xhprof-0.9.4.tgz",
:homebrew_path => "/test/boxen/homebrew",
:phpenv_root => "/test/boxen/phpenv",
:php_version => "5.4.17",
:cache_dir => "/test/boxen/data/php/cache/extensions",
})

should contain_file("/test/boxen/config/php/5.4.17/conf.d/xhprof.ini").with({
:content => File.read("spec/fixtures/xhprof.ini"),
:require => "Php_extension[xhprof for 5.4.17]"
})
end
end
1 change: 1 addition & 0 deletions spec/fixtures/xhprof.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extension=/test/boxen/phpenv/versions/5.4.17/modules/xhprof.so
1 change: 1 addition & 0 deletions templates/extensions/xhprof.ini.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extension=<%= @module_path %>

0 comments on commit 43833fd

Please sign in to comment.