Skip to content

Commit c1477d4

Browse files
authored
Merge pull request #20 from jmjoy/0.2.x-dev
2 parents 8ced243 + 7fe9edc commit c1477d4

File tree

32 files changed

+335
-220
lines changed

32 files changed

+335
-220
lines changed

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.3", path = "../../phper" }
15+
phper = { version = "0.2.0", path = "../../phper" }
1616

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

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

examples/http-client/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ crate-type = ["cdylib"]
1515
anyhow = "1.0.40"
1616
bytes = "1.0.1"
1717
indexmap = "1.6.2"
18-
phper = { version = "0.2.0-alpha.3", path = "../../phper" }
18+
phper = { version = "0.2.0", path = "../../phper" }
1919
reqwest = { version = "0.11.3", features = ["blocking", "cookies"] }
2020
thiserror = "1.0.24"
2121

2222
[dev-dependencies]
23-
phper-test = { version = "0.2.0-alpha.3", path = "../../phper-test" }
23+
phper-test = { version = "0.2.0", path = "../../phper-test" }

examples/http-client/src/client.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::{
2-
errors::HttpClientError, replace_and_get, replace_and_set, request::REQUEST_BUILDER_CLASS_NAME,
2+
errors::HttpClientError,
3+
request::REQUEST_BUILDER_CLASS_NAME,
4+
utils::{replace_and_get, replace_and_set},
35
};
46
use phper::{
57
classes::{ClassEntry, DynamicClass, Visibility},
@@ -50,7 +52,7 @@ pub fn make_client_builder_class() -> DynamicClass<ClientBuilder> {
5052
let state = this.as_mut_state();
5153
let client = replace_and_get(state, ClientBuilder::new(), ClientBuilder::build)?;
5254
let mut object = ClassEntry::<Option<Client>>::from_globals(HTTP_CLIENT_CLASS_NAME)?
53-
.new_object_without_construct();
55+
.init_object()?;
5456
*object.as_mut_state() = Some(client);
5557
Ok::<_, HttpClientError>(object)
5658
},
@@ -79,7 +81,7 @@ pub fn make_client_class() -> DynamicClass<Option<Client>> {
7981
let request_builder = client.get(url);
8082
let mut object =
8183
ClassEntry::<Option<RequestBuilder>>::from_globals(REQUEST_BUILDER_CLASS_NAME)?
82-
.new_object_without_construct();
84+
.init_object()?;
8385
*object.as_mut_state() = Some(request_builder);
8486
Ok::<_, HttpClientError>(object)
8587
},
@@ -95,7 +97,7 @@ pub fn make_client_class() -> DynamicClass<Option<Client>> {
9597
let request_builder = client.post(url);
9698
let mut object =
9799
ClassEntry::<Option<RequestBuilder>>::from_globals(REQUEST_BUILDER_CLASS_NAME)?
98-
.new_object_without_construct();
100+
.init_object()?;
99101
*object.as_mut_state() = Some(request_builder);
100102
Ok::<_, HttpClientError>(object)
101103
},

examples/http-client/src/errors.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
use phper::{
2-
classes::{ClassEntry, DynamicClass, StatelessClassEntry},
3-
errors::Throwable,
4-
};
1+
use phper::classes::{ClassEntry, DynamicClass};
52

63
const EXCEPTION_CLASS_NAME: &'static str = "HttpClient\\HttpClientException";
74

8-
#[derive(thiserror::Error, Debug)]
5+
#[derive(Debug, thiserror::Error, phper::Throwable)]
6+
#[throwable_class(EXCEPTION_CLASS_NAME)]
97
pub enum HttpClientError {
108
#[error(transparent)]
9+
#[throwable(transparent)]
1110
Phper(#[from] phper::Error),
1211

1312
#[error(transparent)]
@@ -20,15 +19,6 @@ pub enum HttpClientError {
2019
ResponseHadRead,
2120
}
2221

23-
impl Throwable for HttpClientError {
24-
fn class_entry(&self) -> &StatelessClassEntry {
25-
match self {
26-
HttpClientError::Phper(e) => e.class_entry(),
27-
_ => ClassEntry::from_globals(EXCEPTION_CLASS_NAME).unwrap(),
28-
}
29-
}
30-
}
31-
3222
pub fn make_exception_class() -> DynamicClass<()> {
3323
let mut exception_class = DynamicClass::new(EXCEPTION_CLASS_NAME);
3424
exception_class.extends("Exception");

examples/http-client/src/lib.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use crate::{
55
response::make_response_class,
66
};
77
use phper::{modules::Module, php_get_module};
8-
use std::mem::replace;
98

109
pub mod client;
1110
pub mod errors;
1211
pub mod request;
1312
pub mod response;
13+
pub mod utils;
1414

1515
#[php_get_module]
1616
pub fn get_module() -> Module {
@@ -28,12 +28,3 @@ pub fn get_module() -> Module {
2828

2929
module
3030
}
31-
32-
fn replace_and_set<T>(t: &mut T, init: T, f: impl FnOnce(T) -> T) {
33-
let x = f(replace(t, init));
34-
let _ = replace(t, x);
35-
}
36-
37-
fn replace_and_get<T, R>(t: &mut T, init: T, f: impl FnOnce(T) -> R) -> R {
38-
f(replace(t, init))
39-
}

examples/http-client/src/request.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{errors::HttpClientError, replace_and_get, response::RESPONSE_CLASS_NAME};
1+
use crate::{errors::HttpClientError, response::RESPONSE_CLASS_NAME, utils::replace_and_get};
22
use phper::{
33
classes::{ClassEntry, DynamicClass, Visibility},
44
objects::Object,
@@ -23,8 +23,8 @@ pub fn make_request_builder_class() -> DynamicClass<Option<RequestBuilder>> {
2323
|this, _arguments| {
2424
let state = this.as_mut_state();
2525
let response = replace_and_get(state, None, |builder| builder.unwrap().send())?;
26-
let mut object = ClassEntry::<Option<Response>>::from_globals(RESPONSE_CLASS_NAME)?
27-
.new_object_without_construct();
26+
let mut object =
27+
ClassEntry::<Option<Response>>::from_globals(RESPONSE_CLASS_NAME)?.init_object()?;
2828
*object.as_mut_state() = Some(response);
2929
Ok::<_, HttpClientError>(object)
3030
},

examples/http-client/src/response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{errors::HttpClientError, replace_and_get};
1+
use crate::{errors::HttpClientError, utils::replace_and_get};
22
use indexmap::map::IndexMap;
33
use phper::{
44
classes::{DynamicClass, Visibility},

examples/http-client/src/utils.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use std::mem::replace;
2+
3+
pub fn replace_and_set<T>(t: &mut T, init: T, f: impl FnOnce(T) -> T) {
4+
let x = f(replace(t, init));
5+
let _ = replace(t, x);
6+
}
7+
8+
pub fn replace_and_get<T, R>(t: &mut T, init: T, f: impl FnOnce(T) -> R) -> R {
9+
f(replace(t, init))
10+
}

examples/logging/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.3", path = "../../phper" }
15+
phper = { version = "0.2.0", path = "../../phper" }
1616

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

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

phper-alloc/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "phper-alloc"
3-
version = "0.2.0-alpha.3"
3+
version = "0.2.0"
44
authors = ["jmjoy <[email protected]>"]
55
edition = "2018"
66
description = "Alloc related items for phper crate."
@@ -11,7 +11,7 @@ keywords = ["php", "alloc"]
1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

1313
[dependencies]
14-
phper-sys = { version = "0.2.0-alpha.3", path = "../phper-sys" }
14+
phper-sys = { version = "0.2.0", path = "../phper-sys" }
1515

1616
[build-dependencies]
17-
phper-build = { version = "0.2.0-alpha.3", path = "../phper-build" }
17+
phper-build = { version = "0.2.0", path = "../phper-build" }

0 commit comments

Comments
 (0)