phuby 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +23 -0
- data/CHANGELOG.rdoc +6 -0
- data/Manifest.txt +35 -0
- data/README.rdoc +96 -0
- data/Rakefile +23 -0
- data/bin/phrack +50 -0
- data/bin/phuby +3 -0
- data/bin/phuby_server +12 -0
- data/ext/phuby/extconf.rb +24 -0
- data/ext/phuby/phuby.c +11 -0
- data/ext/phuby/phuby.h +14 -0
- data/ext/phuby/phuby_array.c +92 -0
- data/ext/phuby/phuby_array.h +9 -0
- data/ext/phuby/phuby_conversions.c +92 -0
- data/ext/phuby/phuby_conversions.h +12 -0
- data/ext/phuby/phuby_runtime.c +243 -0
- data/ext/phuby/phuby_runtime.h +11 -0
- data/lib/phuby.rb +9 -0
- data/lib/phuby/array.rb +24 -0
- data/lib/phuby/events.rb +19 -0
- data/lib/phuby/php_handler.rb +96 -0
- data/lib/phuby/rails.rb +47 -0
- data/lib/phuby/runtime.rb +69 -0
- data/php.patch +145 -0
- data/test/assets/hello_world.php +6 -0
- data/test/assets/htdocs/index.php +22 -0
- data/test/helper.rb +19 -0
- data/test/test_array.rb +101 -0
- data/test/test_handlers.rb +49 -0
- data/test/test_header_sent.rb +25 -0
- data/test/test_nil.rb +10 -0
- data/test/test_object.rb +57 -0
- data/test/test_php_handler.rb +56 -0
- data/test/test_phuby.rb +90 -0
- data/test/test_runtime.rb +77 -0
- metadata +151 -0
data/test/test_object.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestObject < Phuby::TestCase
|
4
|
+
class FunObject
|
5
|
+
attr_reader :called, :values
|
6
|
+
def initialize
|
7
|
+
@called = false
|
8
|
+
@values = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def hello
|
12
|
+
@called = true
|
13
|
+
end
|
14
|
+
|
15
|
+
def value x
|
16
|
+
@values << x
|
17
|
+
end
|
18
|
+
|
19
|
+
def saying
|
20
|
+
"hello"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_stringio
|
25
|
+
Phuby::Runtime.php do |rt|
|
26
|
+
rt['x'] = StringIO.new('')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_method_call
|
31
|
+
x = FunObject.new
|
32
|
+
Phuby::Runtime.php do |rt|
|
33
|
+
rt['x'] = x
|
34
|
+
rt.eval('$x->hello();')
|
35
|
+
end
|
36
|
+
assert x.called
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_method_call_with_args
|
40
|
+
x = FunObject.new
|
41
|
+
Phuby::Runtime.php do |rt|
|
42
|
+
rt['x'] = x
|
43
|
+
rt.eval('$x->value("foo");')
|
44
|
+
rt.eval('$x->value("bar");')
|
45
|
+
end
|
46
|
+
assert_equal %w{ foo bar }, x.values
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_return_value
|
50
|
+
x = FunObject.new
|
51
|
+
Phuby::Runtime.php do |rt|
|
52
|
+
rt['x'] = x
|
53
|
+
rt.eval('$y = $x->saying();')
|
54
|
+
assert_equal 'hello', rt['y']
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestPHPHandler < Phuby::TestCase
|
4
|
+
FakeServer = Struct.new(:config)
|
5
|
+
|
6
|
+
class FakeRequest
|
7
|
+
attr_accessor :request_uri, :query, :path, :meta_vars, :cookies
|
8
|
+
def initialize uri
|
9
|
+
@request_uri = URI.parse "http://localhost#{uri}"
|
10
|
+
@query = @request_uri.query ? Hash[
|
11
|
+
*@request_uri.query.split('&').map { |param| param.split('=') }.flatten
|
12
|
+
] : {}
|
13
|
+
@path = @request_uri.path
|
14
|
+
@meta_vars = {}
|
15
|
+
@cookies = {}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class FakeResponse < Struct.new(:body, :headers)
|
20
|
+
def [] k
|
21
|
+
headers[k]
|
22
|
+
end
|
23
|
+
|
24
|
+
def []= k,v
|
25
|
+
headers[k] = v
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup
|
30
|
+
@server = FakeServer.new(
|
31
|
+
:DocumentRoot => HTDOCS_DIR
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_get
|
36
|
+
req = FakeRequest.new('/index.php?a=b&c=phuby')
|
37
|
+
res = FakeResponse.new('', {})
|
38
|
+
|
39
|
+
handler = Phuby::PHPHandler.new @server
|
40
|
+
handler.do_GET req, res
|
41
|
+
|
42
|
+
assert_match 'Get Params', res.body
|
43
|
+
%w{ a b c phuby }.each do |thing|
|
44
|
+
assert_match "<td>#{thing}</td>", res.body
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_headers_happen
|
49
|
+
req = FakeRequest.new('/index.php?a=b&c=phuby')
|
50
|
+
res = FakeResponse.new('', {})
|
51
|
+
|
52
|
+
handler = Phuby::PHPHandler.new @server
|
53
|
+
handler.do_GET req, res
|
54
|
+
assert_not_nil res['Content-type']
|
55
|
+
end
|
56
|
+
end
|
data/test/test_phuby.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestPhuby < Phuby::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@rt = Phuby::Runtime.instance
|
7
|
+
@rt.start
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
super
|
12
|
+
@rt.stop
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_objects_move
|
16
|
+
foo = Object.new
|
17
|
+
@rt['hello'] = foo
|
18
|
+
assert_equal foo, @rt['hello']
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_eval
|
22
|
+
@rt.eval("$hi = 'Hello World';")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_get_return_int
|
26
|
+
@rt.eval("$hi = 2;")
|
27
|
+
assert_equal 2, @rt['hi']
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_get_return_nil
|
31
|
+
@rt.eval("$hi = null;")
|
32
|
+
assert_nil @rt['hi']
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_get_return_float
|
36
|
+
@rt.eval("$hi = 3.14159;")
|
37
|
+
assert_equal 3.14159, @rt['hi']
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_get_return_bool
|
41
|
+
@rt.eval("$hi = true;")
|
42
|
+
assert_equal true, @rt['hi']
|
43
|
+
|
44
|
+
@rt.eval("$hi = false;")
|
45
|
+
assert_equal false, @rt['hi']
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_get_return_string
|
49
|
+
@rt.eval("$hi = 'world';")
|
50
|
+
assert_equal 'world', @rt['hi']
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_set_int
|
54
|
+
assert_equal 10, @rt['hi'] = 10
|
55
|
+
@rt.eval('$hi += 2;')
|
56
|
+
assert_equal 12, @rt['hi']
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_set_bool
|
60
|
+
assert_equal false, @rt['hi'] = false
|
61
|
+
@rt.eval('$hi = !$hi;')
|
62
|
+
assert_equal true, @rt['hi']
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_set_string
|
66
|
+
assert_equal "hello", @rt['hi'] = "hello"
|
67
|
+
@rt.eval('$hi = $hi . " world";')
|
68
|
+
assert_equal 'hello world', @rt['hi']
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_set_float
|
72
|
+
assert_equal 3.14159, @rt['hi'] = 3.14159
|
73
|
+
@rt.eval('$hi += 1.0;')
|
74
|
+
assert_equal 4.14159, @rt['hi']
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_file_handle
|
78
|
+
File.open(File.join(ASSETS_DIR, 'hello_world.php'), 'rb') { |fh|
|
79
|
+
@rt.eval fh
|
80
|
+
}
|
81
|
+
assert_equal 'world', @rt['hi']
|
82
|
+
end
|
83
|
+
|
84
|
+
#def test_mysql
|
85
|
+
# @rt['dbhost'] = 'localhost'
|
86
|
+
# @rt['dbuser'] = 'root'
|
87
|
+
# @rt['dbpassword'] = nil
|
88
|
+
# @rt.eval('@mysql_connect($dbhost, $dbuser, $dbpassword, true);')
|
89
|
+
#end
|
90
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestRuntime < Phuby::TestCase
|
4
|
+
def test___FILE___is_set
|
5
|
+
hw = File.expand_path(File.join(ASSETS_DIR, 'hello_world.php'))
|
6
|
+
Phuby::Runtime.php do |rt|
|
7
|
+
File.open(hw) do |rb|
|
8
|
+
rt.eval(rb)
|
9
|
+
assert_equal hw, rt['my_file']
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_start_stop
|
15
|
+
rt = Phuby::Runtime.instance
|
16
|
+
rt.start
|
17
|
+
rt.stop
|
18
|
+
rt.start
|
19
|
+
rt.stop
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_started
|
23
|
+
rt = Phuby::Runtime.instance
|
24
|
+
rt.start
|
25
|
+
assert rt.started?
|
26
|
+
rt.stop
|
27
|
+
assert !rt.started?
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_block_is_ensured
|
31
|
+
Phuby::Runtime.php do |rt|
|
32
|
+
raise
|
33
|
+
end
|
34
|
+
rescue
|
35
|
+
assert !Phuby::Runtime.instance.started?
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_mutex_lock
|
39
|
+
rt = Phuby::Runtime.instance
|
40
|
+
rt.start
|
41
|
+
|
42
|
+
assert_raises ThreadError do
|
43
|
+
rt.start
|
44
|
+
end
|
45
|
+
|
46
|
+
ensure
|
47
|
+
rt.stop
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_eval_without_start
|
51
|
+
rt = Phuby::Runtime.instance
|
52
|
+
assert_raises Phuby::Runtime::NotStartedError do
|
53
|
+
rt.eval('$foo = 10;')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_get_without_start
|
58
|
+
rt = Phuby::Runtime.instance
|
59
|
+
assert_raises Phuby::Runtime::NotStartedError do
|
60
|
+
rt['foo']
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_set_without_start
|
65
|
+
rt = Phuby::Runtime.instance
|
66
|
+
assert_raises Phuby::Runtime::NotStartedError do
|
67
|
+
rt['foo'] = 'bar'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_eval_php_block
|
72
|
+
Phuby::Runtime.instance.php do |php|
|
73
|
+
php.eval('$foo = 10;')
|
74
|
+
assert_equal 10, php['foo']
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: phuby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Aaron Patterson
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-01 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rubyforge
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 0
|
30
|
+
- 3
|
31
|
+
version: 2.0.3
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: gemcutter
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 5
|
44
|
+
- 0
|
45
|
+
version: 0.5.0
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: hoe
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 2
|
57
|
+
- 5
|
58
|
+
- 0
|
59
|
+
version: 2.5.0
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
description: Phuby wraps PHP in a loving embrace. Exposes a PHP runtime in ruby
|
63
|
+
email:
|
64
|
+
- aaronp@rubyforge.org
|
65
|
+
executables:
|
66
|
+
- phrack
|
67
|
+
- phuby
|
68
|
+
- phuby_server
|
69
|
+
extensions:
|
70
|
+
- ext/phuby/extconf.rb
|
71
|
+
extra_rdoc_files:
|
72
|
+
- Manifest.txt
|
73
|
+
- CHANGELOG.rdoc
|
74
|
+
- README.rdoc
|
75
|
+
files:
|
76
|
+
- .autotest
|
77
|
+
- CHANGELOG.rdoc
|
78
|
+
- Manifest.txt
|
79
|
+
- README.rdoc
|
80
|
+
- Rakefile
|
81
|
+
- bin/phrack
|
82
|
+
- bin/phuby
|
83
|
+
- bin/phuby_server
|
84
|
+
- ext/phuby/extconf.rb
|
85
|
+
- ext/phuby/phuby.c
|
86
|
+
- ext/phuby/phuby.h
|
87
|
+
- ext/phuby/phuby_array.c
|
88
|
+
- ext/phuby/phuby_array.h
|
89
|
+
- ext/phuby/phuby_conversions.c
|
90
|
+
- ext/phuby/phuby_conversions.h
|
91
|
+
- ext/phuby/phuby_runtime.c
|
92
|
+
- ext/phuby/phuby_runtime.h
|
93
|
+
- lib/phuby.rb
|
94
|
+
- lib/phuby/array.rb
|
95
|
+
- lib/phuby/events.rb
|
96
|
+
- lib/phuby/php_handler.rb
|
97
|
+
- lib/phuby/rails.rb
|
98
|
+
- lib/phuby/runtime.rb
|
99
|
+
- php.patch
|
100
|
+
- test/assets/hello_world.php
|
101
|
+
- test/assets/htdocs/index.php
|
102
|
+
- test/helper.rb
|
103
|
+
- test/test_array.rb
|
104
|
+
- test/test_handlers.rb
|
105
|
+
- test/test_header_sent.rb
|
106
|
+
- test/test_nil.rb
|
107
|
+
- test/test_object.rb
|
108
|
+
- test/test_php_handler.rb
|
109
|
+
- test/test_phuby.rb
|
110
|
+
- test/test_runtime.rb
|
111
|
+
has_rdoc: true
|
112
|
+
homepage: http://github.com/tenderlove/phuby
|
113
|
+
licenses: []
|
114
|
+
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options:
|
117
|
+
- --main
|
118
|
+
- README.rdoc
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
- ext
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
version: "0"
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
version: "0"
|
136
|
+
requirements: []
|
137
|
+
|
138
|
+
rubyforge_project: phuby
|
139
|
+
rubygems_version: 1.3.6
|
140
|
+
signing_key:
|
141
|
+
specification_version: 3
|
142
|
+
summary: Phuby wraps PHP in a loving embrace
|
143
|
+
test_files:
|
144
|
+
- test/test_array.rb
|
145
|
+
- test/test_handlers.rb
|
146
|
+
- test/test_header_sent.rb
|
147
|
+
- test/test_nil.rb
|
148
|
+
- test/test_object.rb
|
149
|
+
- test/test_php_handler.rb
|
150
|
+
- test/test_phuby.rb
|
151
|
+
- test/test_runtime.rb
|