Skip to content

Commit

Permalink
Add priority support [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Jun 29, 2022
1 parent 5e7b906 commit 7d84794
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions Abstract/abstract-php-extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ class AbstractPhpExtension < Formula
desc "Abstract class for PHP Extension Formula"
homepage "https://github.com/shivammathur/homebrew-extensions"

def initialize(*)
super
@priority = self.class.priority || "20"
end

def caveats
<<~EOS
To finish installing #{extension} for PHP #{php_version}:
Expand All @@ -22,6 +27,8 @@ def caveats

private

attr_reader :priority

delegate [:php_version, :extension] => :"self.class"

def php_formula
Expand Down Expand Up @@ -61,20 +68,26 @@ def config_filepath
config_scandir_path / "#{extension}.ini"
end

def priority_config_filepath
config_scandir_path / "#{priority}-#{extension}.ini"
end

def safe_phpize
ENV["PHP_AUTOCONF"] = "#{Formula["autoconf"].opt_bin}/autoconf"
ENV["PHP_AUTOHEADER"] = "#{Formula["autoconf"].opt_bin}/autoheader"
system "#{Formula[php_formula].opt_bin}/phpize"
end

def write_config_file
if config_filepath.file?
inreplace config_filepath do |s|
mv config_filepath, priority_config_filepath if config_filepath.exist?

if priority_config_filepath.file?
inreplace priority_config_filepath do |s|
s.gsub!(/^(;)?(\s*)(zend_)?extension=.+$/, "\\1\\2#{extension_type}=\"#{module_path}\"")
end
elsif config_file
config_scandir_path.mkpath
config_filepath.write(config_file)
priority_config_filepath.write(config_file)
end
end

Expand All @@ -99,6 +112,8 @@ def add_expect_lib
class << self
attr_reader :php_version, :extension

attr_rw :priority

def init
class_name = name.split("::").last
matches = /(\w+)AT(\d)(\d)/.match(class_name)
Expand Down

0 comments on commit 7d84794

Please sign in to comment.