Class: Middleman::Php::Injections
- Inherits:
-
Object
- Object
- Middleman::Php::Injections
- Defined in:
- lib/middleman-php/injections.rb
Instance Method Summary collapse
- #add_get(query_string) ⇒ Object
- #add_include_path(source_dir, path_info) ⇒ Object
- #add_post(rack_input) ⇒ Object
- #add_server(source_dir, env) ⇒ Object
- #generate ⇒ Object
-
#initialize(debug = false) ⇒ Injections
constructor
A new instance of Injections.
Constructor Details
#initialize(debug = false) ⇒ Injections
Returns a new instance of Injections.
5 6 7 8 |
# File 'lib/middleman-php/injections.rb', line 5 def initialize debug=false @debug = debug @injections = [] end |
Instance Method Details
#add_get(query_string) ⇒ Object
31 32 33 |
# File 'lib/middleman-php/injections.rb', line 31 def add_get query_string add_parse_str(query_string, '$_GET') end |
#add_include_path(source_dir, path_info) ⇒ Object
35 36 37 38 |
# File 'lib/middleman-php/injections.rb', line 35 def add_include_path source_dir, path_info path = File.dirname(File.join(source_dir, path_info)) add_raw("set_include_path(get_include_path() . PATH_SEPARATOR . '#{path}');") end |
#add_post(rack_input) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/middleman-php/injections.rb', line 24 def add_post rack_input input = rack_input.read unless input.length == 0 add_parse_str(input, '$_POST') end end |
#add_server(source_dir, env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/middleman-php/injections.rb', line 10 def add_server source_dir, env full_path = File.join(source_dir, env['PATH_INFO']) env.merge!({ 'PHP_SELF' => env['PATH_INFO'], 'SCRIPT_NAME' => full_path, 'SCRIPT_FILENAME' => full_path, 'DOCUMENT_ROOT' => source_dir, 'REQUEST_TIME' => Time.now.to_i, 'REQUEST_TIME_FLOAT' => "%.4f" % Time.now.to_f, 'SERVER_ADMIN' => '[email protected]' }) add_parse_str(URI.encode_www_form(env), '$_SERVER') end |
#generate ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/middleman-php/injections.rb', line 40 def generate if @injections.any? injections = "<?php #{@injections.join(' ')} ?>" if @debug puts '== PHP Injections:' puts injections end end return injections || '' end |