Skip to content

Commit 851b06e

Browse files
authored
Merge pull request #9 from jmjoy/0.2.0-alpha.2-dev
2 parents efc6475 + e7f4f6c commit 851b06e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1694
-348
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
tools: php-config
4141

4242
- name: PHP version
43-
run: php-config --version && php-config --phpapi && php --version
43+
run: php-config || true
4444

4545
- name: Install Rust Nightly
4646
uses: actions-rs/toolchain@v1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
Cargo.lock
44
/.cargo
55
/vendor
6+
/core

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ members = [
99

1010
# internal
1111
"examples/hello",
12-
# "examples/mini-curl",
12+
"examples/log",
13+
"examples/http-client",
14+
"tests/integration",
1315
]

README.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,35 @@ A library that allows us to write PHP extensions using pure Rust and using safe
1717

1818
**os**
1919

20-
- linux
20+
-[x] linux
21+
-[ ] macos
22+
-[ ] windows
2123

2224
**php**
2325

2426
*version*
2527

26-
- 7.0
27-
- 7.1
28-
- 7.2
29-
- 7.3
30-
- 7.4
31-
- 8.0
28+
-[x] 7.0
29+
-[x] 7.1
30+
-[x] 7.2
31+
-[x] 7.3
32+
-[x] 7.4
33+
-[x] 8.0
3234

3335
*mode*
3436

35-
- nts
37+
-[x] nts
38+
-[ ] zts
3639

3740
*sapi*
3841

39-
- cli
42+
-[x] cli
43+
-[ ] fpm
44+
45+
*debug*
46+
47+
-[x] disable
48+
-[ ] enable
4049

4150
## Usage
4251

@@ -79,13 +88,16 @@ fn main() {
7988
use phper::{php_get_module, modules::Module};
8089

8190
#[php_get_module]
82-
pub fn get_module(module: &mut Module) {
83-
// set module metadata
84-
module.set_name(env!("CARGO_PKG_NAME"));
85-
module.set_version(env!("CARGO_PKG_VERSION"));
86-
module.set_author(env!("CARGO_PKG_AUTHORS"));
91+
pub fn get_module() -> Module {
92+
let mut module = Module::new(
93+
env!("CARGO_PKG_NAME"),
94+
env!("CARGO_PKG_VERSION"),
95+
env!("CARGO_PKG_AUTHORS"),
96+
);
8797

8898
// ...
99+
100+
module
89101
}
90102
```
91103

examples/hello/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ license = "Unlicense"
1212
crate-type = ["cdylib"]
1313

1414
[dependencies]
15-
phper = { version = "0.2.0-alpha.1", path = "../../phper" }
15+
phper = { version = "0.2.0-alpha.2", path = "../../phper" }
1616

1717
[dev-dependencies]
18-
phper-test = { version = "0.2.0-alpha.1", path = "../../phper-test" }
18+
phper-test = { version = "0.2.0-alpha.2", path = "../../phper-test" }
1919

2020
[build-dependencies]
21-
phper-build = { version = "0.2.0-alpha.1", path = "../../phper-build" }
21+
phper-build = { version = "0.2.0-alpha.2", path = "../../phper-build" }

examples/hello/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE

examples/hello/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ cargo test --release
2626
```bash
2727
cargo run --release -- install
2828
```
29+
30+
## License
31+
32+
[Unlicense](https://github.com/jmjoy/phper/blob/master/LICENSE).

examples/hello/src/lib.rs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
use phper::{
2+
alloc::EBox,
23
arrays::Array,
3-
classes::{StdClass, This},
4+
classes::StdClass,
45
functions::Argument,
56
ini::Policy,
67
modules::{Module, ModuleArgs},
8+
objects::Object,
79
php_get_module,
8-
values::{SetVal, Val},
10+
values::Val,
911
};
1012

1113
fn module_init(_args: ModuleArgs) -> bool {
1214
true
1315
}
1416

15-
fn say_hello(arguments: &mut [Val]) -> impl SetVal {
16-
let name = arguments[0].as_string();
17-
format!("Hello, {}!\n", name)
17+
fn say_hello(arguments: &mut [Val]) -> phper::Result<String> {
18+
let name = arguments[0].as_string_value()?;
19+
Ok(format!("Hello, {}!\n", name))
1820
}
1921

2022
fn throw_exception(_: &mut [Val]) -> phper::Result<()> {
2123
Err(phper::Error::other("I am sorry"))
2224
}
2325

2426
#[php_get_module]
25-
pub fn get_module(module: &mut Module) {
26-
// set module metadata
27-
module.set_name(env!("CARGO_PKG_NAME"));
28-
module.set_version(env!("CARGO_PKG_VERSION"));
29-
module.set_author(env!("CARGO_PKG_AUTHORS"));
27+
pub fn get_module() -> Module {
28+
let mut module = Module::new(
29+
env!("CARGO_PKG_NAME"),
30+
env!("CARGO_PKG_VERSION"),
31+
env!("CARGO_PKG_AUTHORS"),
32+
);
3033

3134
// register module ini
3235
module.add_bool_ini("hello.enable", false, Policy::All);
@@ -48,35 +51,37 @@ pub fn get_module(module: &mut Module) {
4851
|_: &mut [Val]| {
4952
let mut arr = Array::new();
5053

51-
let mut hello_enable = Val::new(Module::get_bool_ini("hello.enable"));
52-
arr.insert("hello.enable", &mut hello_enable);
54+
let hello_enable = Val::new(Module::get_bool_ini("hello.enable"));
55+
arr.insert("hello.enable", hello_enable);
5356

54-
let mut hello_description = Val::new(Module::get_str_ini("hello.description"));
55-
arr.insert("hello.description", &mut hello_description);
57+
let hello_description = Val::new(Module::get_str_ini("hello.description"));
58+
arr.insert("hello.description", hello_description);
5659

57-
arr
60+
EBox::new(arr)
5861
},
5962
vec![],
6063
);
6164

6265
// register classes
6366
let mut foo_class = StdClass::new();
64-
foo_class.add_property("foo", 100);
67+
foo_class.add_property("foo", "100".to_string());
6568
foo_class.add_method(
6669
"getFoo",
67-
|this: &mut This, _: &mut [Val]| {
70+
|this: &mut Object, _: &mut [Val]| -> phper::Result<Val> {
6871
let prop = this.get_property("foo");
69-
Val::from_val(prop)
72+
Ok(Val::new(prop.as_string_value()?))
7073
},
7174
vec![],
7275
);
7376
foo_class.add_method(
7477
"setFoo",
75-
|this: &mut This, arguments: &mut [Val]| {
76-
let prop = this.get_property("foo");
77-
prop.set(&arguments[0]);
78+
|this: &mut Object, arguments: &mut [Val]| -> phper::Result<()> {
79+
this.set_property("foo", arguments[0].as_string_value()?);
80+
Ok(())
7881
},
7982
vec![Argument::by_val("foo")],
8083
);
8184
module.add_class("FooClass", foo_class);
85+
86+
module
8287
}

examples/hello/tests/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{env, path::Path};
55
fn test_php() {
66
test_php_scripts(
77
env!("CARGO_BIN_EXE_hello"),
8-
&[Path::new(env!("CARGO_MANIFEST_DIR"))
8+
&[&Path::new(env!("CARGO_MANIFEST_DIR"))
99
.join("tests")
1010
.join("php")
1111
.join("test.php")],

examples/hello/tests/php/test.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
assert_eq(hello_say_hello("world"), "Hello, world!\n");
88

9-
assert_eq(class_exists("PHPerException"), true);
9+
assert_eq(class_exists("Phper\\OtherException"), true);
1010

1111
try {
1212
hello_throw_exception();
13-
} catch (PHPerException $e) {
13+
} catch (Phper\OtherException $e) {
1414
assert_eq($e->getMessage(), "I am sorry");
1515
}
1616

@@ -20,7 +20,8 @@
2020
]);
2121

2222
$foo = new FooClass();
23-
assert_eq($foo->getFoo(), 100);
23+
// TODO change '100' to 100.
24+
assert_eq($foo->getFoo(), '100');
2425

2526
$foo->setFoo("Hello");
2627
assert_eq($foo->getFoo(), "Hello");

0 commit comments

Comments
 (0)