Class: Middleman::PhpMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-php/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ PhpMiddleware

Returns a new instance of PhpMiddleware.



4
5
6
# File 'lib/middleman-php/middleware.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/middleman-php/middleware.rb', line 8

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