pub fn new_runtime(
kind: RuntimeKind,
) -> Result<Box<dyn PhpRuntime + Send>, PhpError>Examples found in repository?
examples/async_calls.rs (line 6)
4fn main() {
5 let cfg = RuntimeConfig { debug: false, ..Default::default() };
6 let _rt = new_runtime(RuntimeKind::Process(cfg.clone())).unwrap();
7
8 let h1 = ProcRuntime::call_async_with_cfg(cfg.clone(), "greet".to_string(), vec!["Milton".into()]);
9 let h2 = ProcRuntime::call_async_with_cfg(cfg.clone(), "add".to_string(), vec![7.into(), 9.into()]);
10
11 let r1 = h1.join().unwrap().unwrap();
12 let r2 = h2.join().unwrap().unwrap();
13
14 println!("greet: {:?}", r1.result);
15 println!("add: {:?}", r2.result);
16}More examples
examples/macro_calls.rs (line 6)
4fn main() {
5 let cfg = RuntimeConfig { debug: false, ..Default::default() };
6 let mut rt = new_runtime(RuntimeKind::Process(cfg)).unwrap();
7
8 let r1 = php_call!(rt, hello()).unwrap();
9 println!("hello: output={:?} result={:?}", r1.output, r1.result);
10
11 let r2 = php_call!(rt, greet("Milton")).unwrap();
12 println!("greet: output={:?} result={:?}", r2.output, r2.result);
13
14 let r3 = php_eval!(rt, "print('eval works'); return 42;").unwrap();
15 println!("eval: output={:?} result={:?}", r3.output, r3.result);
16
17 let _ = php_include!(rt, "php/bootstrap.php").unwrap();
18}examples/call_any.rs (line 6)
4fn main() -> Result<()> {
5 let cfg = RuntimeConfig { debug: true, ..Default::default() };
6 let mut rt = new_runtime(RuntimeKind::Process(cfg))?;
7
8 let hello = rt.call("hello", &[])?;
9 println!("hello.output = {:?}", hello.output);
10 println!("hello.result = {:?}", hello.result);
11
12 let greet = rt.call("greet", &[PhpValue::from("Milton")])?;
13 println!("greet.output = {:?}", greet.output);
14 println!("greet.result = {:?}", greet.result);
15
16 let add = rt.call("add", &[7.into(), 5.into()])?;
17 println!("add.output = {:?}", add.output);
18 println!("add.result = {:?}", add.result);
19
20 let user = rt.call("make_user", &[PhpValue::from("Alice"), PhpValue::from(30)])?;
21 println!("user.output = {:?}", user.output);
22 println!("user.info = {:?}", user.info);
23 println!("user.result = {:?}", user.result);
24
25 let boom = rt.call("risky", &[])?;
26 if let Some(ex) = boom.exception.as_ref() {
27 println!("exception.class = {}", ex.class);
28 println!("exception.message = {}", ex.message);
29 println!("exception.code = {}", ex.code);
30 println!("exception.trace = {}", ex.trace);
31 println!("exception.output = {}", boom.output);
32 }
33
34 Ok(())
35}