Class: Rack::Legacy::Php
Defined Under Namespace
Classes: HtAccess
Instance Attribute Summary
Attributes inherited from Cgi
Instance Method Summary (collapse)
-
- (Php) initialize(app, public_dir = FileUtils.pwd, php_exe = 'php-cgi', htaccess_enabled = true)
constructor
Like Rack::Legacy::Cgi.new except allows an additional argument of which executable to use to run the PHP code.
-
- (Object) run(env, path)
Monkeys with the arguments so that it actually runs PHP's cgi program with the path as an argument to that program.
-
- (Boolean) valid?(path)
Adds extension checking in addition to checks in superclass.
Methods inherited from Cgi
Constructor Details
- (Php) initialize(app, public_dir = FileUtils.pwd, php_exe = 'php-cgi', htaccess_enabled = true)
Like Rack::Legacy::Cgi.new except allows an additional argument of which executable to use to run the PHP code.
use Rack::Legacy::Php, 'public', 'php5-cgi'
11 12 13 14 15 |
# File 'lib/rack/legacy/php.rb', line 11 def initialize(app, public_dir=FileUtils.pwd, php_exe='php-cgi', htaccess_enabled=true) super app, public_dir @php_exe = php_exe @htaccess_enabled = htaccess_enabled end |
Instance Method Details
- (Object) run(env, path)
Monkeys with the arguments so that it actually runs PHP's cgi program with the path as an argument to that program.
26 27 28 29 30 31 32 33 34 |
# File 'lib/rack/legacy/php.rb', line 26 def run(env, path) config = {'cgi.force_redirect' => 0} config.merge! HtAccess.merge_all(path, public_dir) if @htaccess_enabled config = config.collect {|(key, value)| "#{key}=#{value}"} config.collect! {|kv| ['-d', kv]} env['SCRIPT_FILENAME'] = path super env, @php_exe, *config.flatten end |
- (Boolean) valid?(path)
Adds extension checking in addition to checks in superclass.
18 19 20 21 22 |
# File 'lib/rack/legacy/php.rb', line 18 def valid?(path) fp = full_path path [/php$/, /php?\d$/].any? {|ext| ::File.extname(fp) =~ ext} && fp.start_with?(::File. @public_dir) && ::File.file?(fp) end |