@@ -16,100 +16,44 @@ def initialize(installed_php_version, required_php_version)
16
16
end
17
17
18
18
class PhpExtensionFormula < Formula
19
+ NAME_PATTERN = /^Php(?:([57])(\d +))?(.+)/
19
20
def initialize ( *)
20
21
super
21
- end
22
22
23
- def self . init
24
- extension_dsl
25
- end
23
+ if build . without? "homebrew-php"
24
+ installed_php_version = nil
25
+ i = IO . popen ( "#{ phpize } -v" )
26
+ out = i . readlines . join ( "" )
27
+ i . close
28
+ { 53 => 20090626 , 54 => 20100412 , 55 => 20121113 , 56 => 20131106 , 70 => 20151012 , 71 => 20160303 , 72 => 20170718 } . each do |v , api |
29
+ installed_php_version = v . to_s if out . match ( /#{ api } / )
30
+ end
26
31
27
- def install
28
- cd "ext/#{ extension } "
29
- system php_parent . bin /"phpize"
30
- system "./configure" , *configure_args
31
- system "make"
32
- ( lib /module_path ) . install "modules/#{ extension } .so"
33
- end
32
+ raise UnsupportedPhpApiError if installed_php_version . nil?
34
33
35
- def post_install
36
- ext_config_path = etc /"php" /php_parent . php_version /"conf.d" /"ext-#{ extension } .ini"
37
- if ext_config_path . exist?
38
- inreplace ext_config_path ,
39
- /#{ extension_type } =.*$/ , "#{ extension_type } =#{ opt_lib /module_path } /#{ extension } .so"
40
- else
41
- ext_config_path . write <<~EOS
42
- [#{ extension } ]
43
- #{ extension_type } =#{ opt_lib /module_path } /#{ extension } .so
44
- EOS
34
+ required_php_version = php_branch . sub ( "." , "" ) . to_s
35
+ unless installed_php_version == required_php_version
36
+ raise InvalidPhpizeError . new ( installed_php_version , required_php_version )
37
+ end
45
38
end
46
39
end
47
40
48
- test do
49
- assert_match extension . downcase , shell_output ( "#{ php_parent . opt_bin } /php -m" ) . downcase ,
50
- "failed to find extension in php -m output"
51
- end
52
-
53
- private
54
-
55
- def php_parent
56
- self . class . php_parent
57
- end
58
-
59
- def extension
60
- self . class . extension
61
- end
62
-
63
- def extension_type
64
- # extension or zend_extension
65
- "extension"
66
- end
67
-
68
- def module_path
69
- extension_dir = Utils . popen_read ( "#{ php_parent . opt_bin /"php-config" } --extension-dir" ) . chomp
70
- php_basename = File . basename ( extension_dir )
71
- "php/#{ php_basename } "
72
- end
73
-
74
- def configure_args
75
- self . class . configure_args
76
- end
77
-
78
- class << self
79
- NAME_PATTERN = /^Php(?:([57])(\d +))?(.+)/
80
- attr_reader :configure_args , :php_parent , :extension
81
-
82
- def configure_arg ( args )
83
- @configure_args ||= [ ]
84
- @configure_args . concat ( Array ( args ) )
41
+ def self . init
42
+ depends_on "autoconf" => :build
43
+
44
+ option "without-homebrew-php" , "Ignore homebrew PHP and use default instead"
45
+ option "without-config-file" , "Do not install extension config file"
46
+ class_name = name . split ( "::" ) . last
47
+ m = NAME_PATTERN . match ( class_name )
48
+ if m . nil?
49
+ raise "Bad PHP Extension name for #{ class_name } "
50
+ elsif m [ 1 ] . nil?
51
+ parent_name = "php"
52
+ else
53
+ parent_name = "php@" + m . captures [ 0 ..1 ] . join ( "." )
85
54
end
86
55
87
- def extension_dsl
88
- class_name = name . split ( "::" ) . last
89
- m = NAME_PATTERN . match ( class_name )
90
- if m . nil?
91
- raise "Bad PHP Extension name for #{ class_name } "
92
- elsif m [ 1 ] . nil?
93
- parent_name = "php"
94
- else
95
- parent_name = "php@" + m . captures [ 0 ..1 ] . join ( "." )
96
- end
97
-
98
- @php_parent = Formula [ parent_name ]
99
- @extension = m [ 3 ] . gsub ( /([a-z])([A-Z])/ ) do
100
- Regexp . last_match ( 1 ) + "_" + Regexp . last_match ( 2 )
101
- end . downcase
102
- @configure_args = %W[
103
- --with-php-config=#{ php_parent . opt_bin /"php-config" }
104
- ]
105
-
106
- homepage php_parent . homepage + extension
107
- url php_parent . stable . url
108
- send php_parent . stable . checksum . hash_type , php_parent . stable . checksum . hexdigest
109
-
110
- depends_on "autoconf" => :build
111
- depends_on parent_name
112
- end
56
+ depends_on parent_name
113
57
end
114
58
115
59
def php_branch
0 commit comments