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 Buffer,
12 Handled,
14}
15
16pub struct NoOpHooks;
18
19impl ExecutionHooks for NoOpHooks {}
20
21pub struct StreamingCallback<F> {
23 output_fn: F,
24}
25
26impl<F> StreamingCallback<F>
27where
28 F: FnMut(&[u8]),
29{
30 pub fn new(output_fn: F) -> Self {
31 Self { output_fn }
32 }
33}
34
35impl<F> ExecutionHooks for StreamingCallback<F>
36where
37 F: FnMut(&[u8]),
38{
39 fn on_output(&mut self, data: &[u8]) -> OutputAction {
40 (self.output_fn)(data);
41 OutputAction::Handled
42 }
43}
44
45pub trait ExecutionHooks {
50 fn on_context_created(&mut self) {}
52 fn on_request_starting(&mut self) {}
54 fn on_request_started(&mut self) {}
56
57 fn on_script_executing(&mut self, script_path: &Path) {
59 let _ = script_path;
60 }
61
62 fn on_script_executed(&mut self, success: bool) {
64 let _ = success;
65 }
66
67 fn on_output(&mut self, data: &[u8]) -> OutputAction {
69 let _ = data;
70 OutputAction::Buffer
71 }
72
73 fn on_flush(&mut self) {}
75
76 fn on_header(&mut self, name: &str, value: &str) -> bool {
78 let _ = (name, value);
79 true
80 }
81
82 fn on_status(&mut self, code: u16) {
84 let _ = code;
85 }
86
87 fn on_php_message(&mut self, message: &ExecutionMessage) {
89 let _ = message;
90 }
91
92 fn is_connection_alive(&self) -> bool {
94 true
95 }
96
97 fn on_request_finishing(&mut self) {}
99
100 fn on_request_finished(&mut self, result: &ExecutionResult) {
102 let _ = result;
103 }
104}