ripht_php_sapi/execution/
hooks.rs1use std::path::Path;
2
3use super::message::ExecutionMessage;
4use super::result::ExecutionResult;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum OutputAction {
10 Continue,
11 Done,
12}
13
14pub struct NoOpHooks;
15
16impl ExecutionHooks for NoOpHooks {}
17
18pub struct StreamingCallback<F> {
21 output_fn: F,
22}
23
24impl<F> StreamingCallback<F>
25where
26 F: FnMut(&[u8]),
27{
28 pub fn new(output_fn: F) -> Self {
29 Self { output_fn }
30 }
31}
32
33impl<F> ExecutionHooks for StreamingCallback<F>
34where
35 F: FnMut(&[u8]),
36{
37 fn on_output(&mut self, data: &[u8]) -> OutputAction {
38 (self.output_fn)(data);
39 OutputAction::Done
40 }
41}
42
43pub trait ExecutionHooks {
48 fn on_context_created(&mut self) {}
50 fn on_request_starting(&mut self) {}
51 fn on_request_started(&mut self) {}
52
53 fn on_script_executing(&mut self, script_path: &Path) {
55 let _ = script_path;
56 }
57
58 fn on_script_executed(&mut self, success: bool) {
60 let _ = success;
61 }
62
63 fn on_output(&mut self, data: &[u8]) -> OutputAction {
65 let _ = data;
66
67 OutputAction::Continue
68 }
69
70 fn on_flush(&mut self) {}
72
73 fn on_header(&mut self, name: &str, value: &str) -> bool {
75 let _ = (name, value);
76 true
77 }
78
79 fn on_status(&mut self, code: u16) {
81 let _ = code;
82 }
83
84 fn on_php_message(&mut self, message: &ExecutionMessage) {
86 let _ = message;
87 }
88
89 fn is_connection_alive(&self) -> bool {
91 true
92 }
93
94 fn on_request_finishing(&mut self) {}
96
97 fn on_request_finished(&mut self, result: &ExecutionResult) {
99 let _ = result;
100 }
101}