Skip to content

Commit 91721b4

Browse files
committed
Modify README.
1 parent 6ad5417 commit 91721b4

File tree

6 files changed

+238
-14
lines changed

6 files changed

+238
-14
lines changed

README.md

Lines changed: 104 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,116 @@
11
# PHPer
22

3+
[![crates](https://img.shields.io/crates/v/phper?style=flat-square)](https://crates.io/crates/phper)
4+
[![](https://img.shields.io/docsrs/phper?style=flat-square)](https://docs.rs/phper)
5+
36
A library that allows us to write PHP extensions using pure Rust and using safe Rust whenever possible.
47

58
## Requirement
69

7-
- os: linux
8-
- libclang: version >= 9
9-
- php: version in (7.1, 7.2, 7.3, 7.4, 8.0), mode: nts
10+
### Necessary
11+
12+
**libclang** version >= 9
13+
14+
**php** version >= 7
15+
16+
### Tested Support
17+
18+
**os**
19+
20+
- linux
21+
22+
**php**
23+
24+
*version*
25+
26+
- 7.0
27+
- 7.1
28+
- 7.2
29+
- 7.3
30+
- 7.4
31+
- 8.0
32+
33+
*mode*
34+
35+
- nts
36+
37+
*sapi*
38+
39+
- cli
1040

1141
## Usage
1242

13-
Now see [examples](examples).
43+
1. Make sure `libclang` and `php` is installed.
44+
45+
```bash
46+
# If you are using debian like linux system:
47+
sudo apt install libclang-10-dev php-cli
48+
```
49+
50+
2. Create you cargo project, suppose your application is called myapp.
51+
52+
```bash
53+
cargo new myapp
54+
```
55+
56+
3. Add the dependencies and metadata to you Cargo project.
57+
58+
```toml
59+
[lib]
60+
crate-type = ["cdylib"]
61+
62+
[dependencies]
63+
phper = "0.2"
64+
```
65+
66+
4. Add these code to `main.rs`.
67+
68+
```rust
69+
use phper::cmd::make;
70+
71+
fn main() {
72+
make();
73+
}
74+
```
75+
76+
5. Write you owned extension logic in `lib.rs`.
77+
78+
```rust
79+
#[php_get_module]
80+
pub fn get_module(module: &mut Module) {
81+
// set module metadata
82+
module.set_name(env!("CARGO_PKG_NAME"));
83+
module.set_version(env!("CARGO_PKG_VERSION"));
84+
module.set_author(env!("CARGO_PKG_AUTHORS"));
85+
86+
// ...
87+
}
88+
```
89+
90+
6. Build and install, if your php isn't installed globally, you should specify the path of `php-config`.
91+
92+
```bash
93+
# Specify if php isn't installed globally.
94+
export PHP_CONFIG = <Your path of php-config>
95+
96+
# Build libmyapp.so.
97+
cargo build --release
98+
99+
# Install to php extension path, if you install php globally, you should use sudo.
100+
cargo run --release -- install
101+
```
102+
103+
7. Edit your `php.ini`, add the below line.
104+
105+
```ini
106+
extension = myapp
107+
```
108+
109+
8. Enjoy.
110+
111+
## examples
112+
113+
See [examples](examples).
14114

15115
## License
16116

examples/hello/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# hello
2+
3+
Hello world example.
4+
5+
## Environment
6+
7+
```bash
8+
# Specify if php isn't installed globally.
9+
export PHP_CONFIG = <Your path of php-config>
10+
```
11+
12+
## Build
13+
14+
```bash
15+
cargo build --release
16+
```
17+
18+
## Test
19+
20+
```bash
21+
cargo test --release
22+
```
23+
24+
## Install
25+
26+
```bash
27+
cargo run --release -- install
28+
```

examples/hello/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn throw_exception(_: &mut [Val]) -> phper::Result<()> {
2222
}
2323

2424
#[php_get_module]
25-
pub extern "C" fn get_module(module: &mut Module) {
25+
pub fn get_module(module: &mut Module) {
2626
// set module metadata
2727
module.set_name(env!("CARGO_PKG_NAME"));
2828
module.set_version(env!("CARGO_PKG_VERSION"));

phper/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ authors = ["jmjoy <[email protected]>"]
55
edition = "2018"
66
description = "A library that allows us to write PHP extensions using pure Rust and using safe Rust whenever possible."
77
repository = "https://github.com/jmjoy/phper.git"
8+
documentation = "https://docs.rs/phper"
89
license = "Unlicense"
910
readme = "../README.md"
1011
keywords = ["php", "binding", "extension"]

phper/src/functions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ pub const fn create_zend_arg_info(
199199
) -> zend_internal_arg_info {
200200
#[cfg(phper_php_version = "8.0")]
201201
{
202+
use std::ptr::null_mut;
202203
zend_internal_arg_info {
203204
name,
204205
type_: zend_type {

phper/src/lib.rs

Lines changed: 103 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,123 @@
11
#![warn(rust_2018_idioms, clippy::dbg_macro, clippy::print_stdout)]
22

33
/*!
4+
# PHPer
5+
6+
[![crates](https://img.shields.io/crates/v/phper?style=flat-square)](https://crates.io/crates/phper)
7+
[![](https://img.shields.io/docsrs/phper?style=flat-square)](https://docs.rs/phper)
8+
49
A library that allows us to write PHP extensions using pure Rust and using safe Rust whenever possible.
510
6-
***Now the peojct is still under development.***
11+
## Requirement
12+
13+
### Necessary
14+
15+
**libclang** version >= 9
16+
17+
**php** version >= 7
18+
19+
### Tested Support
20+
21+
**os**
22+
23+
- linux
24+
25+
**php**
26+
27+
*version*
728
8-
# Usage
29+
- 7.0
30+
- 7.1
31+
- 7.2
32+
- 7.3
33+
- 7.4
34+
- 8.0
35+
36+
*mode*
37+
38+
- nts
39+
40+
*sapi*
41+
42+
- cli
43+
44+
## Usage
45+
46+
1. Make sure `libclang` and `php` is installed.
47+
48+
```bash
49+
# If you are using debian like linux system:
50+
sudo apt install libclang-10-dev php-cli
51+
```
952
10-
First you have to install `cargo-generate`:
53+
2. Create you cargo project, suppose your application is called myapp.
1154
1255
```bash
13-
cargo install cargo-generate
56+
cargo new myapp
1457
```
1558
16-
Then create a PHP extension project from the [template](https://github.com/jmjoy/phper-ext-skel.git):
59+
3. Add the dependencies and metadata to you Cargo project.
60+
61+
```toml
62+
[lib]
63+
crate-type = ["cdylib"]
64+
65+
[dependencies]
66+
phper = "0.2"
67+
```
68+
69+
4. Add these code to `main.rs`.
70+
71+
```rust
72+
use phper::cmd::make;
73+
74+
fn main() {
75+
make();
76+
}
77+
```
78+
79+
5. Write you owned extension logic in `lib.rs`.
80+
81+
```rust
82+
#[php_get_module]
83+
pub fn get_module(module: &mut Module) {
84+
// set module metadata
85+
module.set_name(env!("CARGO_PKG_NAME"));
86+
module.set_version(env!("CARGO_PKG_VERSION"));
87+
module.set_author(env!("CARGO_PKG_AUTHORS"));
88+
89+
// ...
90+
}
91+
```
92+
93+
6. Build and install, if your php isn't installed globally, you should specify the path of `php-config`.
1794
1895
```bash
19-
cargo generate --git https://github.com/jmjoy/phper-ext-skel.git
96+
# Specify if php isn't installed globally.
97+
export PHP_CONFIG = <Your path of php-config>
98+
99+
# Build libmyapp.so.
100+
cargo build --release
101+
102+
# Install to php extension path, if you install php globally, you should use sudo.
103+
cargo run --release -- install
20104
```
21105
22-
# Notice
106+
7. Edit your `php.ini`, add the below line.
107+
108+
```ini
109+
extension = myapp
110+
```
111+
112+
8. Enjoy.
113+
114+
## examples
115+
116+
See [examples](https://github.com/jmjoy/phper/tree/master/examples).
23117
24-
Now the library don't support `ZTS`, the template is using `thread_local!` instead.
118+
## License
25119
26-
Version `0.1.x` will be a preview version.
120+
[Unlicense](https://github.com/jmjoy/phper/blob/master/LICENSE).
27121
*/
28122

29123
pub mod arrays;

0 commit comments

Comments
 (0)