fn hook_on()

in src/plugin/plugin_swoole.rs [52:80]


    fn hook_on(&self) -> (Box<BeforeExecuteHook>, Box<AfterExecuteHook>) {
        (
            Box::new(|_, execute_data| {
                validate_num_args(execute_data, 2)?;

                let on = execute_data.get_parameter(0);
                if !on.as_z_str().map(|s| s == b"request").unwrap_or_default() {
                    return Ok(Box::new(()));
                }

                // Hack the closure with the
                // [`crate::request::skywalking_hack_swoole_on_request`].
                let closure = execute_data.get_mut_parameter(1);
                let ori_closure = replace(
                    closure,
                    ZVal::from(ZString::new(HACK_SWOOLE_ON_REQUEST_FUNCTION_NAME)),
                );

                ORI_SWOOLE_ON_REQUEST.store(
                    Box::into_raw(Box::new(ori_closure)).cast(),
                    Ordering::Relaxed,
                );
                IS_SWOOLE.store(true, Ordering::Relaxed);

                Ok(Box::new(()))
            }),
            Noop::noop(),
        )
    }