Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jun 16, 2021. It is now read-only.

Commit 66a30da

Browse files
author
zouyi
committed
兼容原来方法
1 parent ec6b986 commit 66a30da

File tree

4 files changed

+940
-2
lines changed

4 files changed

+940
-2
lines changed

Abstract/abstract-php-extension.rb

Lines changed: 149 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
require "formula"
2-
class PhpExtensionFormula < Formula
2+
require File.join(File.dirname(__FILE__), "abstract-php-version")
3+
4+
class UnsupportedPhpApiError < RuntimeError
5+
def initialize
6+
super "Unsupported PHP API Version"
7+
end
8+
end
9+
10+
class InvalidPhpizeError < RuntimeError
11+
def initialize(installed_php_version, required_php_version)
12+
super <<~EOS
13+
Version of phpize (PHP#{installed_php_version}) in $PATH does not support building this extension version (PHP#{required_php_version}). Consider installing with the `--without-homebrew-php` flag.
14+
EOS
15+
end
16+
end
17+
18+
class AbstractPhpExtension < Formula
319
def initialize(*)
420
super
521
end
@@ -95,5 +111,136 @@ def extension_dsl
95111
depends_on parent_name
96112
end
97113
end
98-
end
99114

115+
def php_branch
116+
class_name = self.class.name.split("::").last
117+
matches = /^Php([5,7])([0-9]+)/.match(class_name)
118+
if matches
119+
matches[1] + "." + matches[2]
120+
else
121+
raise "Unable to guess PHP branch for #{class_name}"
122+
end
123+
end
124+
125+
def php_formula
126+
"php" + php_branch.sub(".", "")
127+
end
128+
129+
def safe_phpize
130+
ENV["PHP_AUTOCONF"] = "#{Formula["autoconf"].opt_bin}/autoconf"
131+
ENV["PHP_AUTOHEADER"] = "#{Formula["autoconf"].opt_bin}/autoheader"
132+
system phpize
133+
end
134+
135+
def phpize
136+
if build.without? "homebrew-php"
137+
"phpize"
138+
else
139+
"#{Formula[php_formula].opt_bin}/phpize"
140+
end
141+
end
142+
143+
def phpini
144+
if build.without? "homebrew-php"
145+
"php.ini presented by \"php --ini\""
146+
else
147+
"#{Formula[php_formula].config_path}/php.ini"
148+
end
149+
end
150+
151+
def phpconfig
152+
if build.without? "homebrew-php"
153+
""
154+
else
155+
"--with-php-config=#{Formula[php_formula].opt_bin}/php-config"
156+
end
157+
end
158+
159+
def extension
160+
class_name = self.class.name.split("::").last
161+
matches = /^Php[5,7][0-9](.+)/.match(class_name)
162+
if matches
163+
matches[1].downcase
164+
else
165+
raise "Unable to guess PHP extension name for #{class_name}"
166+
end
167+
end
168+
169+
def extension_type
170+
# extension or zend_extension
171+
"extension"
172+
end
173+
174+
def module_path
175+
opt_prefix / "#{extension}.so"
176+
end
177+
178+
def config_file
179+
<<~EOS
180+
[#{extension}]
181+
#{extension_type}="#{module_path}"
182+
EOS
183+
rescue StandardError
184+
nil
185+
end
186+
187+
test do
188+
assert shell_output("#{Formula[php_formula].opt_bin}/php -m").downcase.include?(extension.downcase), "failed to find extension in php -m output"
189+
end
190+
191+
def caveats
192+
caveats = ["To finish installing #{extension} for PHP #{php_branch}:"]
193+
194+
if build.without? "config-file"
195+
caveats << " * Add the following line to #{phpini}:\n"
196+
caveats << config_file
197+
else
198+
caveats << " * #{config_scandir_path}/#{config_filename} was created,"
199+
caveats << " do not forget to remove it upon extension removal."
200+
end
201+
202+
caveats << <<-EOS
203+
* Validate installation via one of the following methods:
204+
*
205+
* Using PHP from a webserver:
206+
* - Restart your webserver.
207+
* - Write a PHP page that calls "phpinfo();"
208+
* - Load it in a browser and look for the info on the #{extension} module.
209+
* - If you see it, you have been successful!
210+
*
211+
* Using PHP from the command line:
212+
* - Run `php -i "(command-line 'phpinfo()')"`
213+
* - Look for the info on the #{extension} module.
214+
* - If you see it, you have been successful!
215+
EOS
216+
217+
caveats.join("\n")
218+
end
219+
220+
def config_path
221+
etc / "php" / php_branch
222+
end
223+
224+
def config_scandir_path
225+
config_path / "conf.d"
226+
end
227+
228+
def config_filename
229+
"ext-" + extension + ".ini"
230+
end
231+
232+
def config_filepath
233+
config_scandir_path / config_filename
234+
end
235+
236+
def write_config_file
237+
if config_filepath.file?
238+
inreplace config_filepath do |s|
239+
s.gsub!(/^(;)?(\s*)(zend_)?extension=.+$/, "\\1\\2#{extension_type}=\"#{module_path}\"")
240+
end
241+
elsif config_file
242+
config_scandir_path.mkpath
243+
config_filepath.write(config_file)
244+
end
245+
end
246+
end

Abstract/abstract-php-phar.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
require "formula"
2+
require File.join(File.dirname(__FILE__), "../Requirements/php-meta-requirement")
3+
require File.join(File.dirname(__FILE__), "../Requirements/phar-requirement")
4+
5+
class AbstractPhpPhar < Formula
6+
def initialize(*)
7+
super
8+
end
9+
10+
def self.init
11+
depends_on PhpMetaRequirement
12+
depends_on PharRequirement
13+
end
14+
15+
def phar_file
16+
class_name = self.class.name.split("::").last
17+
class_name.downcase + ".phar"
18+
end
19+
20+
def phar_bin
21+
class_name = self.class.name.split("::").last
22+
class_name.downcase
23+
end
24+
25+
def phar_wrapper
26+
<<~EOS
27+
#!/usr/bin/env bash
28+
/usr/bin/env php -d allow_url_fopen=On -d detect_unicode=Off #{libexec}/#{@real_phar_file} "$@"
29+
EOS
30+
end
31+
32+
def install
33+
if phar_file == phar_bin
34+
@real_phar_file = phar_file + ".phar"
35+
File.rename(phar_file, @real_phar_file)
36+
else
37+
@real_phar_file = phar_file
38+
end
39+
40+
libexec.install @real_phar_file
41+
(libexec/phar_bin).write phar_wrapper
42+
chmod 0755, (libexec/phar_bin)
43+
bin.install_symlink (libexec/phar_bin)
44+
end
45+
46+
test do
47+
which phar_bin
48+
end
49+
end

Abstract/abstract-php-version.rb

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
class AbstractPhpVersion < Formula
2+
module PhpdbgDefs
3+
PHPDBG_SRC_TARBALL = "https://github.com/krakjoe/phpdbg/archive/v0.3.2.tar.gz".freeze
4+
PHPDBG_CHECKSUM = {
5+
:sha256 => "feab6e29ef9a490aa53332fe014e8026d89d970acc5105f37330b2f31e711bbd",
6+
}.freeze
7+
end
8+
9+
module Php53Defs
10+
PHP_SRC_TARBALL = "https://php.net/get/php-5.3.29.tar.bz2/from/this/mirror".freeze
11+
PHP_GITHUB_URL = "https://github.com/php/php-src.git".freeze
12+
PHP_VERSION = "5.3.29".freeze
13+
PHP_BRANCH = "PHP-5.3".freeze
14+
15+
PHP_CHECKSUM = {
16+
:sha256 => "c4e1cf6972b2a9c7f2777a18497d83bf713cdbecabb65d3ff62ba441aebb0091",
17+
}.freeze
18+
end
19+
20+
module Php54Defs
21+
PHP_SRC_TARBALL = "https://php.net/get/php-5.4.45.tar.bz2/from/this/mirror".freeze
22+
PHP_GITHUB_URL = "https://github.com/php/php-src.git".freeze
23+
PHP_VERSION = "5.4.45".freeze
24+
PHP_BRANCH = "PHP-5.4".freeze
25+
26+
PHP_CHECKSUM = {
27+
:sha256 => "4e0d28b1554c95cfaea6fa2b64aac85433f158ce72bb571bcd5574f98f4c6582",
28+
}.freeze
29+
end
30+
31+
module Php55Defs
32+
PHP_SRC_TARBALL = "https://php.net/get/php-5.5.38.tar.bz2/from/this/mirror".freeze
33+
PHP_GITHUB_URL = "https://github.com/php/php-src.git".freeze
34+
PHP_VERSION = "5.5.38".freeze
35+
PHP_BRANCH = "PHP-5.5".freeze
36+
37+
PHP_CHECKSUM = {
38+
:sha256 => "473c81ebb2e48ca468caee031762266651843d7227c18a824add9b07b9393e38",
39+
}.freeze
40+
end
41+
42+
module Php56Defs
43+
PHP_SRC_TARBALL = "https://php.net/get/php-5.6.33.tar.bz2/from/this/mirror".freeze
44+
PHP_GITHUB_URL = "https://github.com/php/php-src.git".freeze
45+
PHP_VERSION = "5.6.33".freeze
46+
PHP_BRANCH = "PHP-5.6".freeze
47+
48+
PHP_CHECKSUM = {
49+
:sha256 => "07f696a9761dcd839e2045c95c3a4d2ffb52c54417477cca9d30a14975b831cc",
50+
}.freeze
51+
end
52+
53+
module Php70Defs
54+
PHP_SRC_TARBALL = "https://php.net/get/php-7.0.27.tar.bz2/from/this/mirror".freeze
55+
PHP_GITHUB_URL = "https://github.com/php/php-src.git".freeze
56+
PHP_VERSION = "7.0.27".freeze
57+
PHP_BRANCH = "PHP-7.0".freeze
58+
59+
PHP_CHECKSUM = {
60+
:sha256 => "99fa2563bb4c4c1cde9febe87cfe97324227d7b4b8828f2e936e507127394131",
61+
}.freeze
62+
end
63+
64+
module Php71Defs
65+
PHP_SRC_TARBALL = "https://php.net/get/php-7.1.14.tar.bz2/from/this/mirror".freeze
66+
PHP_GITHUB_URL = "https://github.com/php/php-src.git".freeze
67+
PHP_VERSION = "7.1.14".freeze
68+
PHP_BRANCH = "PHP-7.1".freeze
69+
70+
PHP_CHECKSUM = {
71+
:sha256 => "63b2fd139ed7656756b0fa290bc42f8fff854723c3d2710a700e646370c581f4",
72+
}.freeze
73+
end
74+
75+
module Php72Defs
76+
PHP_SRC_TARBALL = "https://php.net/get/php-7.2.2.tar.bz2/from/this/mirror".freeze
77+
PHP_GITHUB_URL = "https://github.com/php/php-src.git".freeze
78+
PHP_VERSION = "7.2.2".freeze
79+
PHP_BRANCH = "PHP-7.2".freeze
80+
81+
PHP_CHECKSUM = {
82+
:sha256 => "f841ac58e17471f2241ea892b34edb01dc9b93ad9f661ffe4e3f1f476a8f4aee",
83+
}.freeze
84+
end
85+
end

0 commit comments

Comments
 (0)