Class: Ionize::Php::Environment::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/ionize/environment/application.rb

Class Method Summary collapse

Instance Method Summary collapse

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

#exitObject

Raises:



31
32
33
# File 'lib/ionize/environment/application.rb', line 31

def exit
  raise ScriptExit
end

#GETObject



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

#POSTObject



23
24
25
# File 'lib/ionize/environment/application.rb', line 23

def POST
  @post ||= @request.POST
end


35
36
37
# File 'lib/ionize/environment/application.rb', line 35

def print(text)
  @output << text
end

#SERVERObject



27
28
29
# File 'lib/ionize/environment/application.rb', line 27

def SERVER
  @server ||= @requeset.SERVER
end