diff --git a/examples/complex/config.m4 b/examples/complex/config.m4
new file mode 100644
index 0000000..34465fe
--- /dev/null
+++ b/examples/complex/config.m4
@@ -0,0 +1,70 @@
+dnl Copyright (c) 2022 PHPER Framework Team
+dnl PHPER is licensed under Mulan PSL v2.
+dnl You can use this software according to the terms and conditions of the Mulan
+dnl PSL v2. You may obtain a copy of Mulan PSL v2 at:
+dnl http://license.coscl.org.cn/MulanPSL2
+dnl THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
+dnl KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+dnl NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+dnl See the Mulan PSL v2 for more details.
+
+PHP_ARG_ENABLE([complex],
+ [whether to enable hello support],
+ [AS_HELP_STRING([--enable-complex],
+ [Enable complex support])],
+ [no])
+
+dnl If not enable, `cargo build` run with argument `--release`.
+PHP_ARG_ENABLE([cargo_debug], [whether to enable cargo debug mode],
+[ --enable-cargo-debug Enable cargo debug], no, no)
+
+if test "$PHP_hello" != "no"; then
+ dnl Check cargo command exists or not.
+ AC_PATH_PROG(CARGO, cargo, no)
+ if ! test -x "$CARGO"; then
+ AC_MSG_ERROR([cargo command missing, please reinstall the cargo distribution])
+ fi
+
+ AC_DEFINE(HAVE_complex, 1, [ Have complex support ])
+
+ PHP_NEW_EXTENSION(complex, [ ], $ext_shared)
+
+ CARGO_MODE_FLAGS="--release"
+ CARGO_MODE_DIR="release"
+
+ if test "$PHP_CARGO_DEBUG" != "no"; then
+ CARGO_MODE_FLAGS=""
+ CARGO_MODE_DIR="debug"
+ fi
+
+ cat >>Makefile.objects<< EOF
+all: cargo_build
+
+clean: cargo_clean
+
+cargo_build:
+ # Build the extension file
+ PHP_CONFIG=$PHP_PHP_CONFIG cargo build $CARGO_MODE_FLAGS
+
+ # Copy the extension file from target dir to modules
+ if [[ -f ./target/$CARGO_MODE_DIR/libcomplex.dylib ]] ; then \\
+ cp ./target/$CARGO_MODE_DIR/libcomplex.dylib ./modules/complex.so ; fi
+ if [[ -f ./target/$CARGO_MODE_DIR/libcomplex.so ]] ; then \\
+ cp ./target/$CARGO_MODE_DIR/libcomplex.so ./modules/complex.so ; fi
+
+cargo_clean:
+ cargo clean
+
+.PHONY: cargo_build cargo_clean
+EOF
+
+ dnl Symbolic link the files for `cargo build`
+ AC_CONFIG_LINKS([ \
+ Cargo.lock:Cargo.lock \
+ Cargo.toml:Cargo.toml \
+ build.rs:build.rs \
+ stubs:stubs \
+ src:src \
+ tests:tests \
+ ])
+fi
diff --git a/examples/complex/package.xml b/examples/complex/package.xml
new file mode 100644
index 0000000..c047bb2
--- /dev/null
+++ b/examples/complex/package.xml
@@ -0,0 +1,64 @@
+
+
+
+ complex
+ pecl.php.net
+ Hello world example a bit complex.
+ The Hello world example of phper.
+
+ jmjoy
+ jmjoy
+ jmjoy@apache.org
+ yes
+
+ 1970-01-01
+
+ 0.0.0
+ 0.0.0
+
+
+ stable
+ stable
+
+ MulanPSL-2.0
+ Release notes.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 8.1.0
+
+
+ 1.4.0
+
+
+
+ complex
+
+
+
+
diff --git a/examples/complex/src/lib.rs b/examples/complex/src/lib.rs
index 323354e..5828c5a 100644
--- a/examples/complex/src/lib.rs
+++ b/examples/complex/src/lib.rs
@@ -27,10 +27,7 @@ use phper::objects::StateObj;
use phper::{modules::Module, php_get_module, values::ZVal, zend_args};
fn say_hello(arguments: &mut [ZVal]) -> phper::Result {
- let name = &mut arguments[0];
- name.convert_to_string();
- let name = name.as_z_str().unwrap().to_str()?;
-
+ let name = arguments[0].as_z_str().unwrap().to_str()?;
Ok(format!("Hello, {name}!\n"))
}
@@ -47,14 +44,14 @@ pub fn get_module() -> Module {
);
// register module ini
- module.add_ini("complex.enable", false, Policy::All);
- module.add_ini("complex.num", 100, Policy::All);
- module.add_ini("complex.ratio", 1.5, Policy::All);
- module.add_ini(
- "complex.description",
- "hello world.".to_owned(),
- Policy::All,
- );
+ // module.add_ini("complex.enable", false, Policy::All);
+ // module.add_ini("complex.num", 100, Policy::All);
+ // module.add_ini("complex.ratio", 1.5, Policy::All);
+ // module.add_ini(
+ // "complex.description",
+ // "hello world.".to_owned(),
+ // Policy::All,
+ // );
// register hook functions
module.on_module_init(|_info| {});
@@ -66,13 +63,13 @@ pub fn get_module() -> Module {
"Complex\\say_hello",
zend_args!(arginfo_Complex_say_hello),
say_hello,
+ )
+ .add_function(
+ "Complex\\throw_exception",
+ zend_args!(arginfo_Complex_throw_exception),
+ throw_exception,
);
// .add_function(
- // "Complex\\throw_exception",
- // zend_args!(arginfo_Complex_throw_exception),
- // throw_exception,
- // )
- // .add_function(
// "Complex\\get_all_ini",
// zend_args!(arginfo_Complex_get_all_ini),
// |_: &mut [ZVal]| {
@@ -83,30 +80,30 @@ pub fn get_module() -> Module {
//
// let complex_description =
// ZVal::from(ini_get::