rack-php-session 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Adam Daniels
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ rack-php-session
2
+ ================
3
+
4
+ Exposes a PHP session (read-only) to Rack applications
5
+
6
+
7
+ Installation
8
+ ------------
9
+ gem install rack-php-session
10
+
11
+
12
+ Dependencies
13
+ ------------
14
+ * [php-serialize](http://www.aagh.net/projects/ruby-php-serialize)
15
+
16
+
17
+ Usage
18
+ -----
19
+ In a Rack environment:
20
+
21
+ require 'rack/php-session'
22
+ use Rack::PHPSession
23
+
24
+ run app
25
+
26
+ In your application
27
+
28
+ env['php.session'] => { } # Returns a Hash of the PHP Session contents
29
+
30
+ In a Rails environment add in 'config/environment.rb' the following:
31
+
32
+ config.middleware.use Rack::PHPSession
33
+
34
+ Limitations
35
+ -----------
36
+ * The PHP session is currently read-only.
37
+ * The Rack application must be able to read PHP session files. In PHP configurations
38
+ that utilize suPHP, this is trivial as session files are stored as the current user.
39
+ Standard mod_php configurations may result in permission problems.
40
+ * The PHP Session ID must be known -- this is generally stored in a cookie so the Rack
41
+ application must run on the same domain as the PHP application (easily achievable
42
+ using Passenger or a Proxy method).
43
+
44
+
45
+ Note on Patches/Pull Requests
46
+ -----------------------------
47
+ * Fork the project.
48
+ * Make your feature addition or bug fix.
49
+ * Add tests for it. This is important so I don't break it in a
50
+ future version unintentionally.
51
+ * Commit, do not mess with rakefile, version, or history.
52
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
53
+ * Send me a pull request. Bonus points for topic branches.
54
+
55
+
56
+ Copyright
57
+ ---------
58
+ Copyright (c) 2010 Adam Daniels. See LICENSE for details.
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rack-php-session"
8
+ gem.summary = %Q{Read-only access to PHP Sessions from Rack Applications}
9
+ gem.description = %Q{Exposes a PHP Session (read-only) to Rack applications}
10
+ gem.email = "adam@mediadrive.ca"
11
+ gem.homepage = "http://github.com/adam12/rack-php-session"
12
+ gem.authors = ["Adam Daniels"]
13
+ gem.add_dependency 'php-serialize'
14
+ gem.add_development_dependency "yard", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+
19
+ Jeweler::RubyforgeTasks.new do |t|
20
+ t.doc_task = :yardoc
21
+ end
22
+
23
+ rescue LoadError
24
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
25
+ end
26
+
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'lib' << 'test'
30
+ test.pattern = 'test/**/test_*.rb'
31
+ test.verbose = true
32
+ end
33
+
34
+ begin
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ end
41
+ rescue LoadError
42
+ task :rcov do
43
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
44
+ end
45
+ end
46
+
47
+ task :test => :check_dependencies
48
+
49
+ task :default => :test
50
+
51
+ begin
52
+ require 'yard'
53
+ YARD::Rake::YardocTask.new
54
+ rescue LoadError
55
+ task :yardoc do
56
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
57
+ end
58
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'rack/php-session')
3
+ require 'sinatra/base'
4
+
5
+ use Rack::Reloader
6
+ use Rack::Lint
7
+ use Rack::ShowExceptions
8
+ use Rack::PHPSession
9
+
10
+ class App < Sinatra::Base
11
+ get '/' do
12
+ "<pre>" + env.to_yaml + "</pre>"
13
+ end
14
+ end
15
+
16
+ map '/' do
17
+ run App.new
18
+ end
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'rack', 'php-session')
@@ -0,0 +1,30 @@
1
+ require 'php_serialize'
2
+
3
+ module Rack
4
+ # Exposes a PHP Session in Rack Applications as a Hash
5
+
6
+ class PHPSession
7
+ # @param [Hash] options the options to configure the middleware
8
+ # @option options [String] :session_name ('PHPSESSID') The name of the PHP Session
9
+ # @option options [String] :session_file_path ('.') The folder where PHP Session files are stored
10
+
11
+ def initialize(app, options = {})
12
+ @app = app
13
+ @options = { :session_name => 'PHPSESSID', :session_file_path => '.' }.merge(options)
14
+ end
15
+
16
+ def call(env, options = {})
17
+ req = Request.new(env)
18
+
19
+ session_id = req.cookies[@options[:session_name]]
20
+ session_file = ::File.join(@options[:session_file_path], "sess_#{session_id}")
21
+
22
+ if ::File.exists?(session_file)
23
+ contents = ::File.read(session_file)
24
+ env['php.session'] = (contents.nil? || contents.empty?) ? Hash.new : PHP.unserialize(contents)
25
+ end
26
+
27
+ @app.call(env)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rack-php-session}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Adam Daniels"]
12
+ s.date = %q{2010-05-20}
13
+ s.description = %q{Exposes a PHP Session (read-only) to Rack applications}
14
+ s.email = %q{adam@mediadrive.ca}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.markdown",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "example/config.ru",
27
+ "lib/rack-php-session.rb",
28
+ "lib/rack/php-session.rb",
29
+ "rack-php-session.gemspec",
30
+ "test/fixtures/sess_b6c1556e31e663f35b042c8b8369b75e",
31
+ "test/fixtures/sess_empty",
32
+ "test/helper.rb",
33
+ "test/test_rack-php-session.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/adam12/rack-php-session}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.6}
39
+ s.summary = %q{Read-only access to PHP Sessions from Rack Applications}
40
+ s.test_files = [
41
+ "test/helper.rb",
42
+ "test/test_rack-php-session.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<php-serialize>, [">= 0"])
51
+ s.add_development_dependency(%q<yard>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<php-serialize>, [">= 0"])
54
+ s.add_dependency(%q<yard>, [">= 0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<php-serialize>, [">= 0"])
58
+ s.add_dependency(%q<yard>, [">= 0"])
59
+ end
60
+ end
61
+
@@ -0,0 +1 @@
1
+ uid|s:1:"1";upw|s:32:"fc34cbc639d6f616f6a43daa3451ab7a";
File without changes
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'rack/test'
4
+
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ require 'rack-php-session'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+
3
+ class TestRackPhpSession < Test::Unit::TestCase
4
+ include Rack::Test::Methods
5
+
6
+ def app
7
+ @app = Rack::Builder.new {
8
+ use Rack::PHPSession, :session_file_path => File.join(File.dirname(__FILE__), 'fixtures')
9
+ run lambda {|env| [200, {'Content-Type' => 'text/plain', 'Content-Length' => '12'}, ["Hello World!"] ] }
10
+ }.to_app
11
+ end
12
+
13
+ def test_no_php_session_without_cookie
14
+ get '/'
15
+ assert ! last_request.env.include?('php.session')
16
+ end
17
+
18
+ def test_php_session_with_cookie
19
+ get '/', nil, { 'HTTP_COOKIE' => 'PHPSESSID=b6c1556e31e663f35b042c8b8369b75e' }
20
+ assert last_request.env.include?('php.session')
21
+ end
22
+
23
+ def test_php_session_hash_is_valid
24
+ get '/', nil, { 'HTTP_COOKIE' => 'PHPSESSID=b6c1556e31e663f35b042c8b8369b75e' }
25
+ assert_equal Hash["uid" => "1", "upw" => "fc34cbc639d6f616f6a43daa3451ab7a"], last_request.env['php.session']
26
+ end
27
+
28
+ def test_empty_session_file_should_return_empty_hash
29
+ get '/', nil, { 'HTTP_COOKIE' => 'PHPSESSID=empty' }
30
+ assert_equal Hash.new, last_request.env['php.session']
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-php-session
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Adam Daniels
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-20 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: php-serialize
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: yard
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :development
43
+ version_requirements: *id002
44
+ description: Exposes a PHP Session (read-only) to Rack applications
45
+ email: adam@mediadrive.ca
46
+ executables: []
47
+
48
+ extensions: []
49
+
50
+ extra_rdoc_files:
51
+ - LICENSE
52
+ - README.markdown
53
+ files:
54
+ - .document
55
+ - .gitignore
56
+ - LICENSE
57
+ - README.markdown
58
+ - Rakefile
59
+ - VERSION
60
+ - example/config.ru
61
+ - lib/rack-php-session.rb
62
+ - lib/rack/php-session.rb
63
+ - rack-php-session.gemspec
64
+ - test/fixtures/sess_b6c1556e31e663f35b042c8b8369b75e
65
+ - test/fixtures/sess_empty
66
+ - test/helper.rb
67
+ - test/test_rack-php-session.rb
68
+ has_rdoc: true
69
+ homepage: http://github.com/adam12/rack-php-session
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options:
74
+ - --charset=UTF-8
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ requirements: []
92
+
93
+ rubyforge_project:
94
+ rubygems_version: 1.3.6
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Read-only access to PHP Sessions from Rack Applications
98
+ test_files:
99
+ - test/helper.rb
100
+ - test/test_rack-php-session.rb