Class: PhpMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/php_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ PhpMiddleware

Returns a new instance of PhpMiddleware.



3
4
5
# File 'lib/php_middleware.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/php_middleware.rb', line 7

def call(env)
  status, headers, response = @app.call(env)

  if env['REQUEST_PATH'] =~ /\.php$/
    response.body.map! do |item|
      `echo #{Shellwords.escape(item)} | php`
    end
    headers['Content-Length'] = response.body.join.length.to_s
    headers['Content-Type'] = 'text/html'
  end

  [status, headers, response]
end