Class: Rack::PHPSession
- Inherits:
-
Object
- Object
- Rack::PHPSession
- Defined in:
- lib/rack/php-session.rb
Overview
Exposes a PHP Session in Rack Applications as a Hash
Instance Method Summary collapse
- #call(env, options = {}) ⇒ Object
-
#initialize(app, options = {}) ⇒ PHPSession
constructor
A new instance of PHPSession.
Constructor Details
#initialize(app, options = {}) ⇒ PHPSession
Returns a new instance of PHPSession.
11 12 13 14 |
# File 'lib/rack/php-session.rb', line 11 def initialize(app, = {}) @app = app @options = { :session_name => 'PHPSESSID', :session_file_path => '.' }.merge() end |
Instance Method Details
#call(env, options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rack/php-session.rb', line 16 def call(env, = {}) req = Request.new(env) session_id = req.[@options[:session_name]] session_file = ::File.join(@options[:session_file_path], "sess_#{session_id}") if ::File.exists?(session_file) contents = ::File.read(session_file) env['php.session'] = (contents.nil? || contents.empty?) ? Hash.new : PHP.unserialize(contents) end @app.call(env) end |