Class: Ionize::Php::Environment::Application
- Inherits:
-
Object
- Object
- Ionize::Php::Environment::Application
- Defined in:
- lib/ionize/environment/application.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
- #exit ⇒ Object
- #GET ⇒ Object
- #header(string) ⇒ Object
-
#initialize(code) ⇒ Application
constructor
A new instance of Application.
- #POST ⇒ Object
- #print(text) ⇒ Object
- #SERVER ⇒ Object
Constructor Details
#initialize(code) ⇒ Application
Returns a new instance of Application.
14 15 16 17 |
# File 'lib/ionize/environment/application.rb', line 14 def initialize(code) @output, @header, @code = "", {}, 200 @php_script = Php.to_ruby(code) end |
Class Method Details
.run(code) ⇒ Object
10 11 12 |
# File 'lib/ionize/environment/application.rb', line 10 def self.run(code) Rack::Handler::Mongrel.run(Application.new(code), :Port => 3000) end |
Instance Method Details
#call(env) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/ionize/environment/application.rb', line 46 def call(env) @request = Rack::Request.new(env) begin instance_eval(@php_script) rescue ScriptExit # Catch an exit() or die() and show that to the user end [@code, @header, @output] end |
#exit ⇒ Object
31 32 33 |
# File 'lib/ionize/environment/application.rb', line 31 def exit raise ScriptExit end |
#GET ⇒ Object
19 20 21 |
# File 'lib/ionize/environment/application.rb', line 19 def GET @get ||= @request.GET end |
#header(string) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/ionize/environment/application.rb', line 39 def header(string) if m = string.match(/Location: (.*)/i) @header["Location"] = m[1] @code = 302 end end |
#POST ⇒ Object
23 24 25 |
# File 'lib/ionize/environment/application.rb', line 23 def POST @post ||= @request.POST end |
#print(text) ⇒ Object
35 36 37 |
# File 'lib/ionize/environment/application.rb', line 35 def print(text) @output << text end |
#SERVER ⇒ Object
27 28 29 |
# File 'lib/ionize/environment/application.rb', line 27 def SERVER @server ||= @requeset.SERVER end |