Class: Middleman::PhpMiddleware

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

Instance Method Summary collapse

Constructor Details

#initialize(app, config = {}) ⇒ PhpMiddleware

Returns a new instance of PhpMiddleware.



6
7
8
9
10
11
# File 'lib/middleman-php/middleware.rb', line 6

def initialize(app, config={})
  @injections = Middleman::Php::Injections.new(true)
  @app        = app
  @config     = config
  @env        = []
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/middleman-php/middleware.rb', line 13

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

  if env['REQUEST_PATH'] =~ /\.php$/
    set_environment(env)
    response.body.map! do |item|
      execute_php(item)
    end
    headers['Content-Length'] = ::Rack::Utils.bytesize(response.body.join).to_s
    headers['Content-Type']   = 'text/html'
    headers['Cache-Control']  = 'no-cache, no-store, must-revalidate'
  end

  [status, headers, response]
end